Android how to used Checkbox

 Checkbox  in Android  

in this article, I am discussing how to use a checkbox in android. and how to get select checkbox value in string its a very easy and simple format to use it. basically checkbox is used for true and false value get and get on your UI 

Step 1:-  Create a project in android and create an activity.

Step 2:- Open your activity XML file and add a checkbox code.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
        <CheckBox
            android:id="@+id/radioOnline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Online "
            />

        <CheckBox
            android:id="@+id/radioCash"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cash" />

        <CheckBox
            android:id="@+id/radioCheck"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cheque"
            />

        <CheckBox
            android:id="@+id/radioBalance"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Balance" />
</LinearLayout>

In these designs, I am using four checkboxes you can use according to your requirements and implement these.

Step 3: Open your java file am implement these

public class CompleteCondition extends AppCompatActivity{

 CheckBox radioOnline,radioCash,radioCheck,radioBalance; 

  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_complete_condition); 
    radioOnline=(CheckBox) findViewById(R.id.radioOnline);
    radioCash=(CheckBox) findViewById(R.id.radioCash);
    radioCheck=(CheckBox) findViewById(R.id.radioCheck);
    radioBalance=(CheckBox) findViewById(R.id.radioBalance);
    radioOnline.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
    radioCheck.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            

        }
    });
    radioCash.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            
        }
    });
    radioBalance.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

 } }

 

 

You may also like...