Reputation: 622
In my application I have to show all list item on clicking Textbox.
I have tried AutoCompleteTextView
without entering text but its not working.
Is there any other widget in Android to achieve this situation?
Please suggest me.
Thanks,
Upvotes: 3
Views: 1142
Reputation: 436
Okay for AutoCompleteTextView, try this way :
In XML Layout:
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="65dp"
android:ems="10" >
In MainActivity,
private AutoCompleteTextView actv;
actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
The next thing you need to do is to specify the list of suggestion items to be displayed. You can specify the list items as a string array in java or in strings.xml.
String[] xyzvalues= getResources().
getStringArray(R.array.list_of_xyzvalues);
ArrayAdapter adapter = new ArrayAdapter
(this,android.R.layout.simple_list_item_1,xyzvalues);
actv.setAdapter(adapter);
Hope this helps.
Upvotes: 2
Reputation: 184
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="65dp"
android:ems="10" >
private AutoCompleteTextView actv;
actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
String[] xyzvalues= getResources().
getStringArray(R.array.list_of_xyzvalues);
ArrayAdapter adapter = new ArrayAdapter
(this,android.R.layout.simple_list_item_1,xyzvalues);
actv.setAdapter(adapter);
Try this working on my machine..
Upvotes: 1