开发者

creating autocomplete in android

开发者 https://www.devze.com 2023-04-05 04:23 出处:网络
I want to create a AutoCompleteTextView in android. The problem is that I want to show whole list of data when user selects AutoComplete开发者_如何学编程TextView and start filtering data as user types

I want to create a AutoCompleteTextView in android. The problem is that I want to show whole list of data when user selects AutoComplete开发者_如何学编程TextView and start filtering data as user types the letters.Please help me in doing this.


Well here is an way how you can do that,

declare an String array -

String[] array = new String[]{"first","second","third","fourth"};

Now, initialize the Adapter with the source.

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                            android.R.layout.simple_dropdown_item_1line,array);

Finally fetch the AutoCompleteTextView id from your xml and set the adapter.

AutoCompleteTextView mView = (AutoCompleteTextView) 
                                             findViewById(R.id.myAutoTextView);
mView.setAdapter(adapter);
0

精彩评论

暂无评论...
验证码 换一张
取 消