自动完成文本查看重音词

Autocompletetextview accented words

我的自动完成视图与 Web 服务连接。当我的 autocompletetextview 加载数据集时,例如:

巴塞罗那 塞维利亚 加的斯 卡斯特利翁 马德里 卡斯蒂利亚 卡斯蒂利亚

当我写"Ca"时,只有这个选项可用

卡斯特利翁 卡斯蒂利亚 卡斯蒂利亚

这个不显示重音字词(加的斯)。

这是我的代码

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());
        }
    }

我想输入字符 "a" 并得到包含字符 "a"、"á"、" â", ...

谢谢!

您必须创建自定义适配器并包含一个自定义过滤器,您可以在其中将重音字符替换为普通字符(á-a、é-e、í-i、...)。

您可以在此处找到自定义实现:Diacritics/international characters in AutoCompleteTextView。特别注意 getFilter() 方法和 HRArrayFilter class(在代码底部)。