I'm trying to automatically switch between dropdown menus.
I have two drop-down menus, when I select the first menu, the second menu content changes depending on this menu, I want it to automatically switch to the second menu and show the list content.
However, it goes to the second menu but does not show its content.
It appears when I click again.
My codes are below. Can you help me?
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/dropDownListOuterAccounts"
style="@style/MyDropDownMenuOuterStyle"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar">
<AutoCompleteTextView
android:id="@+id/dropDownListAccounts"
style="@style/MyEditTextInputInnerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adapter="@{arrayAdapterAccounts}"
android:hint="@string/choose_account"
android:inputType="none"
tools:ignore="SpeakableTextPresentCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/dropDownListOuterSubaccounts"
style="@style/MyDropDownMenuOuterStyle"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dropDownListOuterAccounts">
<AutoCompleteTextView
android:id="@+id/dropDownListSubaccounts"
style="@style/MyEditTextInputInnerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adapter="@{arrayAdapterSubaccounts}"
android:hint="@string/choose_subaccount"
android:inputType="none"
tools:ignore="SpeakableTextPresentCheck" />
</com.google.android.material.textfield.TextInputLayout>
binding.dropDownListAccounts.setOnItemClickListener((parent, view, position, id) -> {
binding.dropDownListOuterAccounts.setHelperText(accountList.get(position).getAccountTypeName());
binding.dropDownListSubaccounts.setText(null);
binding.dropDownListOuterSubaccounts.setHelperText(null);
subaccountsList.set(
subaccountList
.stream()
.filter(subaccounts -> subaccounts.getAccountId().equals(accountList.get(position).getAccountId())).collect(Collectors.toList())
);
List<String> subaccountNames =
subaccountsList.get()
.stream()
.map(Subaccounts::getSubaccountName)
.collect(Collectors.toList());
binding.setArrayAdapterSubaccounts(
new ArrayAdapter<>(
requireContext(),
com.google.android.material.R.layout.support_simple_spinner_dropdown_item,
subaccountNames));
binding.dropDownListSubaccounts.setFocusable(true);
binding.dropDownListSubaccounts.setFocusableInTouchMode(true);
binding.dropDownListSubaccounts.requestFocus();
binding.dropDownListSubaccounts.performClick();
});