Last active
August 16, 2021 07:43
-
-
Save fonix232/6553f66d17746dca5d062eecf40e8b3b to your computer and use it in GitHub Desktop.
Revisions
-
fonix232 revised this gist
May 7, 2019 . 2 changed files with 27 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ <com.google.android.material.textfield.TextInputLayout android:id="@+id/tilGender" style="@style/AppTheme.DropDownMenu" android:prompt="@string/label_gender" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tilLastName"> <AutoCompleteTextView android:hint="@string/label_gender" android:layout_width="match_parent" android:layout_height="wrap_content" entries="@{@stringArray/genders}" value="@={viewModel.gender}" android:editable="false"/> </com.google.android.material.textfield.TextInputLayout> 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ <style name="AppTheme.DropDownMenu" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"> <item name="android:layout_width">0dp</item> <item name="android:layout_height">wrap_content</item> <item name="android:layout_marginTop">@dimen/margin_regular</item> <item name="android:layout_marginBottom">@dimen/margin_regular</item> <item name="android:layout_marginStart">@dimen/margin_large</item> <item name="android:layout_marginEnd">@dimen/margin_large</item> <item name="hintTextColor">@color/colorpalette_blue</item> <item name="boxStrokeColor">@color/outlined_stroke_color</item> </style> -
fonix232 created this gist
May 7, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ @BindingAdapter("valueAttrChanged") fun AutoCompleteTextView.setListener(listener: InverseBindingListener?) { this.onItemSelectedListener = if (listener != null) { object : AdapterView.OnItemSelectedListener { override fun onNothingSelected(parent: AdapterView<*>?) { listener.onChange() } override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { listener.onChange() } } } else { null } } @get:InverseBindingAdapter(attribute = "value") @set:BindingAdapter("value") var AutoCompleteTextView.selectedValue: Any? get() = if (listSelection != ListView.INVALID_POSITION) adapter.getItem(listSelection) else null set(value) { val newValue = value ?: adapter.getItem(0) setText(newValue.toString(), true) if (adapter is ArrayAdapter<*>) { val position = (adapter as ArrayAdapter<Any?>).getPosition(newValue) listSelection = position } } @BindingAdapter("entries", "itemLayout", "textViewId", requireAll = false) fun AutoCompleteTextView.bindAdapter(entries: Array<Any?>, @LayoutRes itemLayout: Int?, @IdRes textViewId: Int?) { val adapter = when { itemLayout == null -> { ArrayAdapter(context, R.layout.item_dropdown, R.id.dropdownText, entries) } textViewId == null -> { ArrayAdapter(context, itemLayout, entries) } else -> { ArrayAdapter(context, itemLayout, textViewId, entries) } } setAdapter(adapter) }