0

Is it possible to provide values to the AutoCompleteTextView in XML / via resources, therefore without setting an adapter in code?

I want to use the AutoCompleteTextView as part of an exposed dropdown menu, so all values shall be shown at once and no filtering shall happen. Also all values to be shown are known at compile time.

stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270

2 Answers2

2

I think you can do that by using the list via Resource and implementing it in AutoCompleteTextView passing by the adapter.

See the example here :

public class CountriesActivity extends Activity {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         setContentView(R.layout.countries);

         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                 android.R.layout.simple_dropdown_item_1line, COUNTRIES);
         AutoCompleteTextView textView = (AutoCompleteTextView)
                 findViewById(R.id.countries_list);
         textView.setAdapter(adapter);
     }

     Resources res = getResources();
     private static final String[] COUNTRIES = res.getStringArray(R.array.planets_array);
 }

Hope this could help you or any one else .

Omar Amaoun
  • 526
  • 1
  • 3
  • 20
-1

Yes its possible. There is a method showDropDown() which you can call.

Try something like

autoCompleteTextView.showDropDown()

Reference : https://developer.android.com/reference/android/widget/AutoCompleteTextView.html#showDropDown()

VVB
  • 7,363
  • 7
  • 49
  • 83