1

My autocompletexview connect with WebServices. When my autocompletextview load the dataset, for example:

Barcelona Sevilla Cádiz Castellon Madrid Castilleja Castilla

When I write "Ca" , only this options are available

Castellon Castilleja Castilla

This dont show accents words ( Cádiz).

Here is my code

public class MainActivity extends Activity {

    InputStream is=null;
    String result=null;
    String line=null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        StrictMode.ThreadPolicy policy= new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);

        try
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("https://www.aaaaaa.com/aaaaaa.php");
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
            Log.e("Pass 1", "connection success ");
        }
        catch(Exception e)
        {
            Log.e("Fail 1", e.toString());
            Toast.makeText(getApplicationContext(), "Invalid IP Address",
                    Toast.LENGTH_LONG).show();
        }

        try
        {
            BufferedReader reader = new BufferedReader
                    (new InputStreamReader(is,"iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();

            while ((line = reader.readLine()) != null)
            {
                sb.append(line + "\n");
            }

            is.close();
            result = sb.toString();
            Log.e("Pass 2", "connection success ");
        }
        catch(Exception e)
        {
            Log.e("Fail 2", e.toString());
        }

        try
        {
            JSONArray JA=new JSONArray(result);
            JSONObject json= null;
            final String[] str1 = new String[JA.length()];

            for(int i=0;i<JA.length();i++)
            {
                json=JA.getJSONObject(i);
                str1[i]=json.getString("nombre");
            }

            final AutoCompleteTextView text = (AutoCompleteTextView)
                    findViewById(R.id.autoCompleteTextView1);
            final List<String> list = new ArrayList<String>();

            for(int i=0;i<str1.length;i++)
            {
                list.add(str1[i]);
            }

            Collections.sort(list);


            ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>
                    (getApplicationContext(), android.R.layout.simple_spinner_item, list);

            dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            text.setThreshold(1);
            text.setAdapter(dataAdapter);

            text.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    // TODO Auto-generated method stub
                    Toast.makeText(getBaseContext(), list.get(arg2).toString(),
                            Toast.LENGTH_SHORT).show();
                }
            });
        }
        catch(Exception e)
        {
            Log.e("Fail 3", e.toString());
        }
    }

I would like to write the character "a" and get results that include the characters "a", "á", "â", ...

Thanks!

tipiwiny
  • 399
  • 1
  • 3
  • 18
  • I think this problem is on server side rather than app, isn't it? – deadfish Aug 27 '15 at 09:34
  • I think its special character problem – IntelliJ Amiya Aug 27 '15 at 09:36
  • IMHO op should create separate column in db with normalized words. So searching would be on normalized column but ther result would be from not normalized. This could be used in the oposite way. In app You write "ć" but before sending char to server You first normalize to "c" and search. – deadfish Aug 27 '15 at 09:41
  • @deadfish The application works well, in the previous example, if I type "Cá" then the option "Cádiz" if is displayed, the problem is that the keyboard app is not usually used accented characters. thanks – tipiwiny Aug 27 '15 at 10:23

1 Answers1

1

You have to create you custom adapter and include a custom Filter where you replace the accented characters by plain characters (á-a, é-e, í-i,...).

You can find a custom implementation here: Diacritics/international characters in AutoCompleteTextView. Pay special attention to the getFilter() method and the HRArrayFilter class (at the bottom of the code).

Community
  • 1
  • 1
Rafa0809
  • 1,733
  • 21
  • 24