0% found this document useful (0 votes)
101 views2 pages

Android Checkbox Selection App

The document shows how to create an Android application with five checkboxes to select programming languages and display the selected options in a toast notification. It includes the XML layout file, Java activity code, and strings resource file.

Uploaded by

Harshal Bhangale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views2 pages

Android Checkbox Selection App

The document shows how to create an Android application with five checkboxes to select programming languages and display the selected options in a toast notification. It includes the XML layout file, Java activity code, and strings resource file.

Uploaded by

Harshal Bhangale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Develop an android application to show five checkboxes and toast selected checkboxes

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/msg"
style="@style/[Link]"
android:layout_margin="10dp"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/chkAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/android"
style="@style/[Link]"/>
<CheckBox
android:id="@+id/chkJava"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/java"
style="@style/[Link]"/>
<CheckBox
android:id="@+id/chkPhp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/php"
style="@style/[Link]"/>
<CheckBox
android:id="@+id/chkCpp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cpp"
style="@style/[Link]"/>
<CheckBox
android:id="@+id/chkC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/c"
style="@style/[Link]"/>
<Button android:id="@+id/btnDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display"
android:layout_marginTop="20dp"
android:onClick="showSelected"/>
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private CheckBox chkAndroid, chkJava, chkPhp, chkCpp, chkC;
@Override
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
chkAndroid = findViewById([Link]);
chkJava = findViewById([Link]);
chkPhp = findViewById([Link]);
chkCpp = findViewById([Link]);
chkC = findViewById([Link]);
}
public void showSelected(View view) {
String selected = "You selected: \n";
if([Link]())
selected += "Android";
if([Link]())
selected += "\nJava";
if([Link]())
selected += "\nPHP";
if([Link]())
selected += "\nCPP";
if([Link]())
selected += "\nC";
[Link]([Link], selected, Toast.LENGTH_SHORT).show();
}
}
[Link]
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CheckBoxApp</string>
<string name="msg">Select your favourite programming languages</string>
<string name="android">Android</string>
<string name="java">Java</string>
<string name="php">PHP</string>
<string name="cpp">CPP</string>
<string name="c">C</string>
</resources>

You might also like