AutoCompleteTextView自动填充文本

布局:

<AutoCompleteTextView
        android:id="@+id/auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:completionThreshold="1" />

代码:

private AutoCompleteTextView auto;
    private ArrayAdapter<String> adapter;
    private List<String> list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        list = new ArrayList<String>();
        list.add("ab");
        list.add("apple");
        adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, list);
        auto = (AutoCompleteTextView) findViewById(R.id.auto);
        auto.setAdapter(adapter);
    }

 

posted @ 2016-04-25 13:01  嘉禾世兴  阅读(484)  评论(0编辑  收藏  举报