Skip to content

Instantly share code, notes, and snippets.

@milhauscz
Created April 21, 2021 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milhauscz/b72fe799e9b93c540822a72d3c4a9135 to your computer and use it in GitHub Desktop.
Save milhauscz/b72fe799e9b93c540822a72d3c4a9135 to your computer and use it in GitHub Desktop.
Example of a material spinner item layout
<?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>
@Hmerman6006
Copy link

I am receiving the following error when initialising the adapter:

Cannot find a setter for <android.widget.ImageView app:isNotGone> that accepts parameter type 'java.lang.Boolean'

If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches

I used the code as is, I just changed namespaces as my directory is not com.example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment