java - 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"
};
}
该列表显示完美,但是当我尝试选择一个项目时,没有任何反应。有没有人有办法解决吗。谢谢 !
解决方案
从您的文件中删除focusable
和。clickable
fixed_amount_list.xml
推荐阅读
- ruby-on-rails - 在 Rails 中,有没有办法从rescue_from 中“短路”?
- powerbi - 添加列时如何防止RANKX重复
- macos - 通过 Catalyst 将 iOS 应用程序移植到 Mac 时如何获得访问文件的权限
- ios - 是否可以从 iPhone CMOS 传感器读取原始电压值?
- bash - 在 shell 脚本中格式化日期 YYYY-MM-DD +DAY + Mounth
- python - 如何在matplotlib中的垂直对齐X轴标签之间放置空间
- javascript - JavaScript 中的 .clientWidth/.width 不适用于 img 标签
- mysql - 尝试创建具有多个表但找不到创建有效主键的解决方案的 NFL 数据库
- css - 如何摆脱 DNN 的 Xcilion 皮肤中的渐变?
- qt - QML 将日期时间字符串转换为 qml 可解析日期在 GMT 时区失败