接口的实现类CommaTokenizer
只能提示一次的小案例:
布局:
<LinearLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android" > <AutoCompleteTextView android:id="@+id/auto" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout>
主Activity:
package com.example.auto; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; public class MainActivity extends Activity { private AutoCompleteTextView autv; private ArrayAdapter<String> adapter; private String[] words ={ "good","very good","hellow","nihao", "how are you","what are you name" }; private void setupView(){ autv = (AutoCompleteTextView) findViewById(R.id.auto); autv.setThreshold(1); autv.setCompletionHint("历史信息..."); adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,words); autv.setAdapter(adapter); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setupView(); } }
布局:
<LinearLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android" > <MultiAutoCompleteTextView android:id="@+id/mautv" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout>主Activity:
package com.example.auto; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.MultiAutoCompleteTextView; public class MainActivity extends Activity { private String[] words ={ "good","very good","hellow","nihao", "how are you","what are you name" }; private MultiAutoCompleteTextView autv; private ArrayAdapter<String> adapter; private void setupView(){ autv = (MultiAutoCompleteTextView)findViewById(R.id.mautv); adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,words); autv.setAdapter(adapter); autv.setThreshold(1); autv.setCompletionHint("搜索结果..."); autv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setupView(); } }