首页 > 解决方案 > Android studio Material design:自动完成不会自动选择项目下拉列表

问题描述

我正在尝试使菜单可选择,菜单工作正常但是当我尝试选择一个项目时没有任何反应,菜单保持固定。

我希望当我选择一个元素时,该值可以自动显示在条目上。

这是我的带有自动完成元素的 xml 文件:

<com.google.android.material.textfield.TextInputLayout
            android:id="@+id/order_transfert_amound_fixed_layout"
            style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/transfert_amount"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginBottom="15dp"
            app:startIconDrawable="@drawable/ic_baseline_monetization_on_24">

            <AutoCompleteTextView
                android:id="@+id/order_transfert_amound_fixed_textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/select_amount"
                android:inputType="none"
                />

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

这是包含我的项目布局的 xml 文件fixed_amount_list.xml :

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:clickable="true"
    android:focusable="true"/>

所以我的 AmountActivity 类包含允许我应用列表:

public class AmountActivity extends AppCompatActivity {

    private AutoCompleteTextView order_transfert_amound_fixed_textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_amount);

         order_transfert_amound_fixed_textView = findViewById(R.id.order_transfert_amound_fixed_textView);
         
         ArrayAdapter<String> adapter = new Adapter(this, R.layout.fixed_amount_list, AMOUNTS);
         order_transfert_amound_fixed_textView.setAdapter(adapter);
    }
    
    private static final String[] AMOUNTS = new String[] {
       "10.00", "15.00", "20.00", "25.00", "30.00"
    };
}

该列表显示完美,但是当我尝试选择一个项目时,没有任何反应。有没有人有办法解决吗。谢谢 !

标签: javaandroidmaterial-design

解决方案


从您的文件中删除focusable和。clickablefixed_amount_list.xml


推荐阅读