我正在尝试用ListView替换MultiAutoCompleteTextView下拉列表,它应该具有与下拉列表相同的功能,这意味着,当我单击其中一个项目时,它应该被添加到MultiAutoCompleteTextView框中,等等,但是过滤了键入时ListView.
所以我想出了这个原始代码没有成功:
filterable_listview.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<MultiAutoCompleteTextView
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:hint="@string/To" android:id="@+id/search_box"></MultiAutoCompleteTextView>
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
AutoCompleteActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.filterable_listview);
manager = new ContactManager();
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, manager.getContacts());
searchEdit = (MultiAutoCompleteTextView) findViewById(R.id.search_box);
searchEdit.addTextChangedListener(filterTextWatcher);
searchEdit.setTokenizer(new SpaceTokenizer());
setListAdapter(adapter);
getListView().setOnItemClickListener(
new ListView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//Here is one issues
searchEdit.append(adapter.getItem(position));
}
});
}
private TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) { …Run Code Online (Sandbox Code Playgroud)