Implementing CheckBox Application in Android with Dr. Sandip Mal

Slide Note
Embed
Share

This tutorial guides you on how to create a CheckBox application in Android using XML code and Java files. Dr. Sandip Mal provides the necessary steps for designing the UI elements, setting up event listeners, and handling user interactions to capture checkbox selections. The XML code snippet and Java file edits demonstrated here will help you understand the process of implementing checkbox functionality in your Android app.


Uploaded on Sep 25, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Check Box Application Dr. Sandip Mal

  2. XML Code <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.example.admin.sandip.checkbox.MainActivity" tools:showIn="@layout/activity_main"> <CheckBox android:id="@+id/checkBox3" android:layout_width="83dp" android:layout_height="wrap_content" android:layout_marginBottom="326dp" android:layout_marginEnd="237dp" android:layout_marginStart="53dp" android:layout_marginTop="17dp" android:text="option 3" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/checkBox2" app:layout_constraintVertical_bias="1.0" /> <CheckBox android:id="@+id/checkBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="430dp" android:layout_marginEnd="251dp" android:layout_marginStart="48dp" android:layout_marginTop="49dp" android:text="Option 1" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.0" /> <CheckBox android:id="@+id/checkBox2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="375dp" android:layout_marginEnd="242dp" android:layout_marginStart="48dp" android:layout_marginTop="23dp" android:text="Option 2" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/checkBox" app:layout_constraintVertical_bias="0.0" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="248dp" android:layout_marginEnd="234dp" android:layout_marginStart="62dp" android:layout_marginTop="30dp" android:text="Submit" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/checkBox3" /> </android.support.constraint.ConstraintLayout>

  3. Edit Java File 1. Declare Variables private CheckBox c1,c2,c3; private Button b; 2. Define a Function public void addListerOnButton(){ c1=(CheckBox)findViewById(R.id.checkBox); c2=(CheckBox)findViewById(R.id.checkBox2); c3=(CheckBox)findViewById(R.id.checkBox3); b=(Button)findViewById(R.id.button); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { StringBuffer s=new StringBuffer(); s.append("option 1").append(c1.isChecked()); s.append("option 2").append(c2.isChecked()); s.append("option 3").append(c3.isChecked()); Toast.makeText(MainActivity.this,s.toString(),Toast.LENGTH_LONG).show(); } }); } 3. Call the function from onCreate() method.

  4. Lab Assignment Create three checkbox with three movie name. write a program to display --- movie is selected if user select single option. If user select multiple option give message You selected multiple option

Related


More Related Content