-
-
Save aungtuntun/c274d1688b6ebe07840e8bcc64ab6deb to your computer and use it in GitHub Desktop.
Android Material Components - Dropdown Menu + Data Binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.widget.ArrayAdapter | |
| import android.widget.AutoCompleteTextView | |
| import androidx.annotation.LayoutRes | |
| import androidx.databinding.BindingAdapter | |
| @BindingAdapter("dropDownItems", "dropDownItemLayout", "dropDownItemsIncludeEmpty", requireAll = false) | |
| fun AutoCompleteTextView.setItems(items: Array<String>?, @LayoutRes layout: Int?, includeEmpty: Boolean?) = | |
| setAdapter( | |
| ArrayAdapter( | |
| context, | |
| layout ?: R.layout.default_dropdown_menu_popup_item, | |
| (if (includeEmpty == true) arrayOf("") else emptyArray()) + (items ?: emptyArray()) | |
| ) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <com.google.android.material.textfield.TextInputLayout | |
| android:id="@+id/status" | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content" | |
| android:hint="@string/contact_editor_hint_status" | |
| app:layout_constraintTop_toBottomOf="@id/name"> | |
| <AutoCompleteTextView | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content" | |
| android:completionThreshold="@{999999}" | |
| android:editable="false" | |
| android:text="@={contact.translatedStatus}" | |
| app:dropDownItemLayout="@{@layout/mtrl_dropdown_menu_popup_item}" | |
| app:dropDownItems="@{Constants.statusValues}" | |
| app:dropDownItemsIncludeEmpty="@{true}" | |
| tools:text="Partner" /> | |
| </com.google.android.material.textfield.TextInputLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment