English 中文(简体)
动态更新 AutoComplete Text 在选定项目后再次下降的观点
原标题:Dynamic updating AutoCompleteTextView popup the drop down again after item selected

I m 动态地更新“FerCompleteTextView”和面临两个问题的Im。

  • 在选定项目时,出现了新的悬 the事件,正如你在以下法典中看到的那样,有人要求获得新的选用物品,因此, on事件使自动裁审会再次显示下降! 是否有解决这一问题的清洁方法?

  • 在我打电话通知DataSetChange()之前,从汽车上获得的结果是,如何做到这一点?

这部法律是:

AutoCompleteTextView acCountry = (AutoCompleteTextView)layout.findViewById(R.id.autoComplete);
final ArrayAdapter<RMAutoComplete.ListItem> countriesAdapter = new ArrayAdapter<RMAutoComplete.ListItem>(this.context,android.R.layout.simple_dropdown_item_1line);
acCountry.setAdapter(countriesAdapter);
acCountry.addTextChangedListener(new TextWatcher() {

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() > 1)
            {
                new AsyncTask<String, Void, List<RMAutoComplete.ListItem>>(){

                    @Override
                    protected List<ListItem> doInBackground(String... params) {
                        List<ListItem> l = null;
                        try {
                            l = location.getCountryData(params[0]);
                        } catch (Exception e) {
                            Log.e(TAG,"error when getCountryData",e);
                        }
                        return l;
                    }

                    @Override
                    protected void onPostExecute(List<ListItem> countries) {
                        countriesAdapter.clear();
                        if (countries != null)
                            for (ListItem listItem : countries) {
                                countriesAdapter.add(listItem);
                            }
                        countriesAdapter.notifyDataSetChanged();
                    }
                }.execute(s.toString());
            }
        }

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

        public void afterTextChanged(Editable s) {}
    }
);
最佳回答

很好地吸收活力的适应者,需要做的是执行习惯(<>Filter等,并超越表演 收集和公布Results方法。

在演练中,创立了FilterResults的新例子,并初步确定了他的价值观和新项目。 (这一方法在新版面上运行!) 例如:

@Override
    protected FilterResults performFiltering(CharSequence constraint) {
        FilterResults fr = null;
        if (constraint != null)
        {
            List<ListItem> list = getFilterdValues(constraint.toString());

            if (list != null)
            {
                fr = new FilterResults();
                fr.values = list;
                fr.count = list.size();
            }
        }
        return fr;
    }

并且,在出版社中,适应者也取得了以下成果:

@Override
    protected void publishResults(CharSequence constraint,
            FilterResults results) {
        AutoCompleteAdapter.this.clear();
        if (results != null)
        {
            if (results.values != null)
            {
                List<ListItem> items = (List<ListItem>) results.values;

                    for (ListItem listItem : items) {
                        AutoCompleteAdapter.this.add(listItem);
                    }

                if (items.size() > 0)
                {
                    AutoCompleteAdapter.this.notifyDataSetChanged();
                    return;
                }
            }
        }
        AutoCompleteAdapter.this.notifyDataSetInvalidated();
    }

同样也是进口的,是您需要定制适应器和超载体。 符合你自己的新习惯 诸如:

public class AutoCompleteAdapter extends ArrayAdapter<RMAutoComplete.ListItem> 
{


private CustomFilter _customFilter = null;

@Override
public Filter getFilter() {

    if (_customFilter == null)
        _customFilter = new CustomFilter();
    return _customFilter;
}


public AutoCompleteAdapter(Context context, int textViewResourceId) {
    super(context, textViewResourceId);

}

}

hope it was helpful for someone..

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签