【问题标题】:MaterialAutoCompleteTextView dropdownmenu/adapter not shownMaterialAutoCompleteTextView 下拉菜单/适配器未显示
【发布时间】:2021-08-05 13:20:42
【问题描述】:

我有一个简单的设置:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="#C9E44B"
 tools:context=".pkgTestforend.DriverAddOptionalDataFragment">

    <com.google.android.material.textfield.TextInputLayout
        style="Theme.MaterialComponents.Light.Bridge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="visible"
        >

        <com.google.android.material.textfield.MaterialAutoCompleteTextView
            android:id="@+id/filled_exposed_dropdown"
            android:layout_width="200dp"
            android:visibility="visible"
            android:layout_height="wrap_content" />

    </com.google.android.material.textfield.TextInputLayout>

</RelativeLayout>

我正在尝试使用简单的适配器使下拉菜单可见:

MaterialAutoCompleteTextView filled_exposed_dropdown;
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    String [] randomArray = new String[3];
    randomArray[0] = " test ";
    randomArray[1] = " values";
    randomArray[2] = " ofcourse";

    ArrayList<String> items = new ArrayList<String>(Arrays.asList(randomArray));
    ArrayAdapter<String> h = new ArrayAdapter(getContext(),R.layout.list_item, items);

    filled_exposed_dropdown = view.findViewById(R.id.filled_exposed_dropdown);
    filled_exposed_dropdown.setAdapter(h);
}

最后但并非最不重要的是我的 list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
  <TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp"
    android:ellipsize="end"
    android:maxLines="1"
    android:textAppearance="?attr/textAppearanceSubtitle1"
    />
</menu>

但是,尝试在启动我的应用程序时显示下拉菜单如下所示:

问题是我只能写一个新项目,但下拉菜单不可见。我错过了什么?大部分代码基于原始 material.io 文档。

【问题讨论】:

    标签: drop-down-menu menu material-design android-adapter google-material-icons


    【解决方案1】:
    filled_exposed_dropdown.showDropDown() 
    

    不见了。 ;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2020-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      相关资源
      最近更新 更多