未能设置新引入的已显示下拉菜单的起始值。
我正在尝试获取第一个值集,但是当我尝试使用"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"有人知道怎么解决这个问题吗?
发布于 2020-02-17 19:08:03
在设置适配器方法后在下面尝试
dropdown_sex.setText(loadCenterList.get(mViewFlipper.displayedChild - 1), false)发布于 2019-07-23 17:31:17
使用mBinding.dropdownSex.setText(*TEXT OF ARRAY ITEM HERE*);
https://stackoverflow.com/questions/56320542
复制相似问题