Created
April 21, 2021 12:45
-
-
Save milhauscz/b72fe799e9b93c540822a72d3c4a9135 to your computer and use it in GitHub Desktop.
Example of a material spinner item layout
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools"> | |
<data> | |
<variable | |
name="item" | |
type="com.example.ExampleItem" /> | |
<variable | |
name="selected" | |
type="Boolean" /> | |
</data> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:padding="@dimen/padding"> | |
<!-- | |
Updates the text and enabled state according to the item. | |
--> | |
<TextView | |
android:id="@+id/text" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:textAppearance="?android:attr/textAppearanceMedium" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
app:layout_constraintEnd_toStartOf="@id/selected_icon" | |
app:layout_constraintHorizontal_chainStyle="spread_inside" | |
app:layout_constrainedWidth="true" | |
app:layout_constraintHorizontal_bias="0" | |
tools:text="Spinner Item" | |
android:text="@{item.text}" | |
android:singleLine="true" | |
android:ellipsize="end" | |
android:enabled="@{item.enabled}" /> | |
<!-- Shown if "selected" is true. --> | |
<ImageView | |
android:id="@+id/selected_icon" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
app:layout_constraintStart_toEndOf="@id/text" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
app:layout_constraintBottom_toBottomOf="parent" | |
android:src="@drawable/ic_done_black_24dp" | |
android:tint="?android:attr/colorAccent" | |
android:contentDescription="@string/general_selected_item_accessibility_description" | |
app:isNotGone="@{selected}" /> | |
</androidx.constraintlayout.widget.ConstraintLayout> | |
</layout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am receiving the following error when initialising the adapter:
I used the code as is, I just changed namespaces as my directory is not
com.example
.