我已经实施了AutoCompleteTextView
如下:
MainActivity.java
...
public static String[] myData=new String[]{"Africa (AF)","America (AFM)","Apple (AMP)"};
text=(AutoCompleteTextView)v.findViewById(R.id.first_state);
ArrayAdapter adapter = new ArrayAdapter(getActivity(),R.layout.autocompletetextview_row,R.id.textViewItem,myData);
text.setAdapter(adapter);
text.setThreshold(1);
text.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
selected_station = (String)parent.getItemAtPosition(position);
//TODO Do something with the selected text
}
});
在布局中AutoCompleteTextView
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:padding="10dp" >
<TextView
android:id="@+id/textViewItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Item name here..."
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>
当我输入“af..”时,它会显示非洲 (AF)选择但不选择美国(AFM).
该数据只是示例数据。这不是我正在使用的AutoCompleteTextView
仅 3 件商品。
编辑:当我删除括号时,它可以正常工作。但我需要保留括号以供进一步使用。