【发布时间】:2020-02-17 19:08:03
【问题描述】:
未能设置新引入的暴露下拉菜单的起始值。
我正在尝试获取第一个值集,但是当我尝试使用“selectedItemPosition”时出现错误,即未找到这些属性。
另外,尝试使用 java 代码实现这一点,给了我一个错误,即没有索引。
// Trying to set it via java code
Binding.dropdownSex.setAdapter(getAdapter(getResources().getStringArray(R.array.fragment_me_spinner_sex)));
mBinding.dropdownSex.setSelection(1); // java.lang.IndexOutOfBoundsException: setSpan (1 ... 1) ends beyond length 0
// just a small method to get the adapter
private ArrayAdapter<String> getAdapter(String[] elements) {
return new ArrayAdapter<>(Objects.requireNonNull(getContext()),
R.layout.dropdown_menu_popup_item,
elements);
}
还有……
<!-- attribute android:selectedItemPosition not found. -->
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="32dp"
android:paddingEnd="32dp"
>
<AutoCompleteTextView
android:id="@+id/dropdown_sex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/sex"
android:focusable="false"
android:cursorVisible="false"
有人知道如何解决这个问题吗?
【问题讨论】:
-
您找到解决方案了吗?我也面临这个问题。