Android学习笔记AutoCompleteTextView的使用

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="文本自动提示" />
    <AutoCompleteTextView 
        android:id="@+id/myAuto"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
</LinearLayout>

 

MainActivity.java

public class MainActivity extends Activity {
    private static final String myData[]=new String[] {"test","testabc","test111","test123"};
    private AutoCompleteTextView myAuto=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,myData);
        this.myAuto=(AutoCompleteTextView)super.findViewById(R.id.myAuto);
        this.myAuto.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

 

posted @ 2013-10-05 10:58  寂静之秋  阅读(158)  评论(0编辑  收藏  举报
哈尔滨八零网