0% found this document useful (0 votes)
19 views3 pages

Pra 11 EX

The document contains an Android application layout and code that allows users to select their favorite programming languages using checkboxes. It includes a LinearLayout with five CheckBoxes for different languages and a Button to display the selected languages. The MainActivity class handles the logic to show a Toast message with the selected options when the button is clicked.

Uploaded by

sammedmohare465
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)
19 views3 pages

Pra 11 EX

The document contains an Android application layout and code that allows users to select their favorite programming languages using checkboxes. It includes a LinearLayout with five CheckBoxes for different languages and a Button to display the selected languages. The MainActivity class handles the logic to show a Toast message with the selected options when the button is clicked.

Uploaded by

sammedmohare465
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
You are on page 1/ 3

Pra:11

Ex:Q.1

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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/TextAppearance.AppCompat.Large"
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/TextAppearance.AppCompat.Headline"/>

<CheckBox
android:id="@+id/chkJava"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/java"
style="@style/TextAppearance.AppCompat.Headline"/>

<CheckBox
android:id="@+id/chkPhp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/php"
style="@style/TextAppearance.AppCompat.Headline"/>

<CheckBox
android:id="@+id/chkCpp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cpp"
style="@style/TextAppearance.AppCompat.Headline"/>

<CheckBox
android:id="@+id/chkC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/c"
style="@style/TextAppearance.AppCompat.Headline"/>

<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>

package com.example.checkboxdemo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private CheckBox chkAndroid, chkJava, chkPhp, chkCpp, chkC;

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

chkAndroid = findViewById(R.id.chkAndroid);
chkJava = findViewById(R.id.chkJava);
chkPhp = findViewById(R.id.chkPhp);
chkCpp = findViewById(R.id.chkCpp);
chkC = findViewById(R.id.chkC);
}

public void showSelected(View view) {


String selected = "You selected: \n";

if(chkAndroid.isChecked())
selected += "Android";

if(chkJava.isChecked())
selected += "\nJava";

if(chkPhp.isChecked())
selected += "\nPHP";

if(chkCpp.isChecked())
selected += "\nCPP";

if(chkC.isChecked())
selected += "\nC";

Toast.makeText(MainActivity.this, selected, Toast.LENGTH_SHORT).show();


}
}

<?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