当您按下该字段时,AutoCompleteTextView 不会显示您的所有选项

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

我正在尝试让名为 autoCategory_bookAutoCompleteTextView 变量显示其所有选项,只需按下该字段即可。

// 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()));

}

你不需要View.onFocusChangeListener:

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