Android:自动提示控件AutoCompleteTextView

废话不多说,简单的分享一下Activity代码:


/*
 * 自动提示功能
 */
public class AutoCompleteTextViewActivity extends Activity {
    /** Called when the activity is first created. */
 AutoCompleteTextView atv=null;
 MultiAutoCompleteTextView matv=null;
 Button but;

 //定义提示内容
 String[] source=new String[]{"android","java","web","html"};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        atv=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
        matv=(MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
        but=(Button) findViewById(R.id.button1);
       
        //定义适配器
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,source);
        //绑定适配器
        atv.setAdapter(adapter);
        //以逗号作为分隔符(否则失效)
        matv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
        matv.setAdapter(adapter);
       but.setOnClickListener(new OnClickListener() {
  
  public void onClick(View v) {

     //验证  

      Toast.makeText(AutoCompleteTextViewActivity.this,"输入的是:"+matv.getText() , Toast.LENGTH_LONG).show();
   
  }
 });
    }
}

你可能感兴趣的:(自动提示控件)