Android AutoCompleteTextView Simple, hard-coded AutoCompleteTextView

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Design (layout XML):

<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" />

Find the view in code after setContentView() (or its fragment or custom view equivalent):

final AutoCompleteTextView myAutoCompleteTextView = 
    (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);

Provide hard-coded data via an adapter:

String[] countries = getResources().getStringArray(R.array.list_of_countries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,countries);
myAutoCompleteTextView.setAdapter(adapter);

Tip: Though the preferred way would be to provide data via a Loader of some kind instead of a hard-coded list like this.



Got any Android Question?