Home > Mobile >  How do I create logic for select all button in android studio
How do I create logic for select all button in android studio

Time:06-14

Here I have list of buttons, in which if they are clicked not ok I have to insert in the sql table as 0 and if clicked ok I have to insert as 1, the customer is asking to include select all except for the buttons which have been selected not ok and insert it into the table How do I use for loop to add all button inputs except for which are not ok using conditional statment*

<?xml version="1.0" encoding="utf-8"?>
        <ScrollView 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"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".Inspection"
            android:orientation="vertical">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            >
        
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.3"
                android:id="@ id/date_ins"
                />
        
            <View
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.01"/>
        
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="EOL Inspection-2"
                android:layout_weight="0.5"
                />
        
            <View
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.01"/>
        
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="Shift A:  Operator"
                android:layout_weight="0.2"
                />
        
        
        </LinearLayout>
        
        
        
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Vehicle Inspection"
                android:layout_gravity="center"
                android:textSize="30dp"
                />
        
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
        
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Vin No:"
                    android:textSize="20dp"/>
                <View
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.01"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.5"
                    android:gravity="center"
                    android:textSize="20dp"
                    android:id="@ id/vin_ins"
        
                    />
        
            </LinearLayout>
        
        
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="15dp">
        
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Inspection Name"
                    android:textSize="20dp"
                    android:background="@drawable/border_2"
        
                    />
                <View
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.01"/>
        
                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="OK"
                    android:textSize="20dp"
                    android:gravity="center"
                    android:layout_weight="0.5"
                    android:background="@drawable/border_2"
                    />
        
                <View
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.01"/>
                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="NOT OK"
                    android:textSize="20dp"
                    android:gravity="center"
                    android:layout_weight="0.5"
                    android:background="@drawable/border_2"
                    />
        
            </LinearLayout>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="BODY SHOP "
                android:layout_gravity="center"
                android:textSize="25dp"
                android:textStyle="bold"
                />
        
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="10dp">
        
                <TextView
                    android:id="@ id/serial_number_punching"
                    android:layout_width="0dp"
                    android:layout_height="75dp"
                    android:textSize="17dp"
                    android:text="Serial Number Punching and Scanning"
                    android:layout_weight="0.8"
                    />
        
                <View
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.01"/>
                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.45"
                    android:text="OK"
                    android:backgroundTint="#807C7C"
                    android:id="@ id/ok_1"
                    android:layout_marginTop="10dp"
                    />
                <View
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.05" />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="NOk"
                    android:id="@ id/nok_1"
                    android:backgroundTint="#807C7C"
                    android:layout_marginTop="10dp"
                    />
        
        
            </LinearLayout>
        
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="10dp">
        
                <TextView
                    android:layout_width="0dp"
                    android:layout_height="110dp"
                    android:textSize="17dp"
                    android:text="Boat Tightening With Chassis ,Front Wind Shield Panel Tightening With Chassis"
                    android:layout_weight="0.8"
                    android:id="@ id/boat_tight"
                    />
        
                <View
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.01"/>
                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.45"
                    android:text="OK"
                    android:id="@ id/ok_2"
                    android:backgroundTint="#807C7C"
                    android:layout_marginTop="20dp"
                    />
                <View
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.05" />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:backgroundTint="#807C7C"
                    android:text="NOk"
                    android:id="@ id/nok_2"
                    android:layout_marginTop="20dp"
                    />
        
        
            </LinearLayout>
        
        
        
    
    

CodePudding user response:

You can't click the button unless you use AccessibilityService. so you need to call a function that's called when clicking the target button.

In your case, you need to call all functions of the button list.

CodePudding user response:

1 - Create a list of all buttons, whether it is getting the items dynamically or statically, up to you.

2 - Create a dictionary, key is button id in the list, value is checkBox.isChecked(). Or, check if the checkbox is checked, and insert in a seperate list all the ids that return a true.

  • Related