【问题标题】:AutoCompleteTextView not showing drop down menu - AndroidAutoCompleteTextView 不显示下拉菜单 - Android
【发布时间】:2020-09-04 11:46:58
【问题描述】:

我已经按照 material.io 构建了一个“公开的下拉菜单”,但没有显示下拉菜单。

我想实现这个: Dropdown (screenshot from material.io)

但是,我目前收到的是:Failed dropdown

当我将“android:inputType="none"”添加到 AutoCompleteTextView 时,我不确定为什么我什至可以在框中输入内容。

这就是我在片段中初始化适配器的方式:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_add, container, false);

    // Initialise drop down list
    ArrayAdapter<String> adapter = new ArrayAdapter<>(
            getContext(),
            R.layout.dropdown_menu_popup_item,
            UNITS
    );

    AutoCompleteTextView unitsExposedDropdown = view.findViewById(R.id.unit_selection);
    unitsExposedDropdown.setAdapter(adapter);

    return view;
}

感谢您的帮助!

编辑:这是我用来构建公开下拉菜单https://material.io/develop/android/components/menu的链接

【问题讨论】:

标签: android drop-down-menu autocompletetextview


【解决方案1】:

不想在框中输入

那你为什么不使用弹出菜单看看这个:

PopupMenu popup = new PopupMenu(youractivity.this, yourbutton);  
                //Inflate the pop up menu
                popup.getMenuInflater().inflate(R.menu.popmenu, popup.getMenu());  
  
                //do something on click 
                popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {  
                    public boolean onMenuItemClick(MenuItem item) {  
                      //do your work here
                    }  
                });  
  
                popup.show();//show it 

要了解更多信息,请参阅https://developer.android.com/reference/android/widget/PopupMenu

【讨论】:

  • 如果可能的话,我更喜欢使用暴露的下拉菜单。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-04
相关资源
最近更新 更多