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

Ex 11

The document contains an XML layout for an Android application with three checkboxes and a button. The Java code defines a MainActivity that initializes these UI elements and displays the selected checkbox texts in a Toast message when the button is clicked. The second checkbox is set to be checked by default.

Uploaded by

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

Ex 11

The document contains an XML layout for an Android application with three checkboxes and a button. The Java code defines a MainActivity that initializes these UI elements and displays the selected checkbox texts in a Toast message when the button is clicked. The second checkbox is set to be checked by default.

Uploaded by

Ravi Pardhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

<CheckBox
android:id="@+id/ch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="chk_ios" />

<CheckBox
android:id="@+id/ch2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="chk_android"
android:checked="true" />

<CheckBox
android:id="@+id/ch3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="chk_windows" />

<Button
android:id="@+id/ch4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn_display" />

</LinearLayout>

package com.example.helloworld;

import android.os.Bundle;
import android.app.Activity;
import android.widget.Button;

import android.view.View;
import android.view.View.OnClickListener;

import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends Activity {


CheckBox ch1,ch2,ch3;
Button b;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ch1=(CheckBox)findViewById(R.id.ch1);
ch2=(CheckBox)findViewById(R.id.ch2);
ch3=(CheckBox)findViewById(R.id.ch3);
b=(Button)findViewById(R.id.ch4);
b.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
StringBuffer result = new StringBuffer();
if(ch1.isChecked()) {
result.append(ch1.getText());
}
if(ch2.isChecked()) {
result.append("\n").append(ch2.getText());
}
if(ch3.isChecked()) {
result.append("\n").append(ch3.getText());
}
Toast.makeText(MainActivity.this, result.toString(),
Toast.LENGTH_LONG).show();
}
});
}
}

You might also like