Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
95 views
in Technique[技术] by (71.8m points)

How to set the switch button checked by comparing the string using data binding android(Java)

I have a model class of this JSON

"individualattributepermissionList": [
            {
                "ATTRIBUTE_NAME": "Age",
                "CUSTOM_PERMISSION": true,
                "GLOBAL_PERMISSION": false,
               
            },
            {
                "ATTRIBUTE_NAME": "CHILD_AGES",
                "CUSTOM_PERMISSION": false,
                "GLOBAL_PERMISSION": false,
            },
        ], 

I have the xml Layout for the age attribute

<RelativeLayout
                    style="@style/mw"
                    android:layout_marginTop="10dp"
                    android:orientation="horizontal"
                    android:layout_marginStart="@dimen/dp_22"
                    android:gravity="center_vertical">

                    <TextView
                        style="@style/text_ww_bold"
                        android:text="@string/age"
                        android:layout_centerVertical="true"
                        android:layout_alignParentStart="true"
                        android:onClick="@{profileVM.selectAge}"/>

                    <androidx.appcompat.widget.SwitchCompat
                        style="@style/switch_30"
                        android:layout_alignParentEnd="true"
                        android:tag="AGE_G"                                    
                        android:onCheckedChanged="@{profileVM.checkedChangedListener}"
                        />

                    <androidx.appcompat.widget.SwitchCompat
                        style="@style/switch_10"
                        android:tag="AGE_C"
                        android:layout_alignParentEnd="true"        
                android:checked="@{profileVM.individualAttributePermission.getCustomPermission}"
                        android:onCheckedChanged="@{profileVM.checkedChangedListener}"
                        />
                </RelativeLayout>

I have the attribute name is age and then I have 2 switch buttons for the age like global and custom switch buttons

I need to compare the attribute name as age and then for global switch i need to set Gobalpermission and for custom switch i need to set the custome permission using data binding or in view model class in android java. How can I compare the attribute age and then set the globalswitch checked or unchecked

question from:https://stackoverflow.com/questions/65951604/how-to-set-the-switch-button-checked-by-comparing-the-string-using-data-binding

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...