AutoCompleteTextView无法在华为设备

时间:2016-08-31 07:34:03

标签: android android-fragments autocomplete

我有一个使用AutoCompleteTextView来显示机场建议的应用程序。我的应用支持两种语言 - 英语和阿拉伯语。我已在AutoCompleteTextView中为此dialog view实施了相同的内容。我使用的代码如下:

final AutoCompleteTextView fromactv  = (AutoCompleteTextView) fromDialog.findViewById(R.id.autoCompleteTextView1d);
            final TextView no_match_tv  = (TextView) fromDialog.findViewById(R.id.tv_no_match);
            final ImageButton close     = (ImageButton) fromDialog.findViewById(R.id.ib_close);
            fromactv.setText(null);
            final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
            OnItemClickListener onitem=new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // TODO Auto-generated method stub
                    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
                    String actvstringfrom = fromactv.getText().toString();

                    String resource[];
                    if(CommonFunctions.lang.equalsIgnoreCase("ar")){
                        resource     = actvstringfrom.split(" \t ");
                        actvstringfrom = resource[0];
                    }

                    strFromCity = actvstringfrom;
                    resource = actvstringfrom.split("-");
                    strFromCode = resource[3];
                    strFromCode = strFromCode.replace(" ", "");

                    tvFromCode.setText(strFromCode);
                    tvFromCity.setText(strFromCity);

                   if(resource[1].toLowerCase().contains("all airport") ||
                            resource[1].toLowerCase().contains("جميع المطار"))
                            allAirportFrom = "Y";
                        else
                            allAirportFrom = "N";

                    Editor editor = sharedpreferences.edit();
                    editor.putString("strFromCode", strFromCode);
                    editor.putString("allAirportFrom", allAirportFrom);
                    editor.commit();

                    fromDialog.dismiss();

                }
            };
            fromactv.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence s, int start, int before,
                        int count) {

                    String filter = s.toString().toLowerCase();
                    listItems = new ArrayList<String>();
                    for (String listItem : arrayAirportList) {
                        if (listItem.toLowerCase().contains(filter))
                        {
                            listItems.add(listItem);
                        }

                    }
                    if (listItems.size() == 0)
                    {
                        if(no_match_tv.getVisibility() == View.GONE)
                            no_match_tv.setVisibility(View.VISIBLE);
                    }
                    else
                    {
                        if(no_match_tv.getVisibility() == View.VISIBLE)
                            no_match_tv.setVisibility(View.GONE);
                    }
                    ArrayAdapter<String> adapt = new ArrayAdapter<String>(getActivity(),
                            R.layout.tv_autocomplete, listItems);
                    fromactv.setAdapter(adapt);
                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                }

                @Override
                public void afterTextChanged(Editable s) {

                }
            });

            fromactv.setOnItemClickListener(onitem);
            fromDialog.show();

此代码适用于除 Honor 设备以外的大多数手机。问题仅在于阿拉伯语版本。有人经历过这样的问题吗?我怎么处理这个?

提前致谢!

0 个答案:

没有答案