Android Databinding : Compare strings in xml

Compare two strings after putting the constant string in side two Back quote ( ` ).

<RadioButton
            android:id="@+id/male"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checked="@{user.gender.equalsIgnoreCase(`male`)}"
            android:text="@string/male"/>

Use string resources

        <RadioButton
            android:id="@+id/male"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checked="@{user.gender.equalsIgnoreCase(@string/male)}"
            android:text="@string/male"/>


Use string constants:

<data>
    <import type="yourfullpackagepath.StringConstants"/>
</data>

        <RadioButton
            android:id="@+id/female"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checked="@{user.gender.equalsIgnoreCase(StringConstants.FEMALE)}"
            android:text="@string/female"/>

No comments:

Post a Comment

Popular Posts