I have question to answer my curiosity. I have implemented dropdown with material design like snippet code xml at the below
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/provinsi_register_form"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/address_register_form">
<AutoCompleteTextView
android:id="@+id/filled_dropdown_provinsi"
style="@style/greySubText"
android:layout_width="match_parent"
android:layout_height="55dp"
android:hint="@string/provinsi_form"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
You can see the result implementation on this link picture result dropdown
for the list, I got from ViewModel like on this snipet code below:
konfirmasiViewModel.provinsi.observe(this, { provinsi ->
for (i in provinsi.indices) {
provinsiNama.add(provinsi[i].provinsi!!)
}
val adapter =
ArrayAdapter(this, R.layout.support_simple_spinner_dropdown_item, provinsiNama)
filled_dropdown_provinsi.setAdapter(adapter)
filled_dropdown_provinsi.setOnItemClickListener { adapterView, view, i, l ->
lifecycleScope.launch {
siscaPreference.saveId(provinsi[i].id!!)
}
prov = provinsi[i].id.toString()
}
})
How to make condition if user doesn't choose anything either click by button or not? Thanks for much attention