Boranoro
Boranoro

Reputation: 69

AutoCompleteTextView does not display all your options when you press the field

I'm trying to make my AutoCompleteTextView variable called autoCategory_book show all of its options just by pressing on the field.

// expected ')', expected ';', expected '(', expected '{', cannot resolve symbol 'view', cannot resolve symbol 'b' unexpected token 
autoCategoty_book.setOnFocusChangeListener(View.OnFocusChangeListener(view , b -> if(b) autoCategory_book.showDropDown()));
    <string-array name="category_book">
        <item> Self help </item>
        <item> Biography </item>
        <item> Education </item>
        <item> Science fiction </item>
        <item> Manual </item>
        <item> Literature </item>
        <item> Romance </item>
    </string-array>
protected void onCreate(Bundle savedInstanceState) {

    AutoCompleteTextView autoCategory_book;
    String[] Category_book;
    
    Category_book = getResources().getStringArray(R.array.category_book);
    
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, Category_book);
    autoCategory_book.setThreshold(0);
    autoCategory_book.setAdapter(adapter);
    autoCategoty_book.setOnFocusChangeListener(View.OnFocusChangeListener(view , b -> if(b) autoCategory_book.showDropDown()));

}

Upvotes: 1

Views: 47

Answers (1)

DJ. Aduvanchik
DJ. Aduvanchik

Reputation: 342

you don't need View.onFocusChangeListener:

autoCategory_book.setOnFocusChangeListener((v, hasFocus) ->{
      if(hasFocus){ autoCategory_book.showDropDown(); 
     );

Upvotes: 1

Related Questions