Android Checkbox Example

ANDROID FOR FRESHERS

Android Checkbox Example

Android Checkbox Example

Java Code(CheckBoxAct)

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

public class CheckBoxAct extends Activity

{
CheckBox checked1,checked2,checked3;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState)

{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_box);
checked1 = (CheckBox)findViewById(R.id.cb1);
checked2 = (CheckBox)findViewById(R.id.cb2);
checked3 = (CheckBox)findViewById(R.id.cb3);
tv = (TextView)findViewById(R.id.textView);
}
public void displayItems(View v)
{
String st1,st2,st3;
if(checked1.isChecked())
{
st1 = checked1.getText().toString();
}
else
{
st1=””;
}
if(checked2.isChecked())
{
st2 = checked2.getText().toString();
}
else
{
st2=””;
}
if(checked3.isChecked())
{
st3 = checked3.getText().toString();
}
else
{
st3=””;
}
tv.setText(st1+”\n”+st2+”\n”+st3);
}
}

 

Layout XML code(activity_check_box)

 <?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.andro.tech.androidproject.CheckBoxAct”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textSize=”@dimen/textsize”
android:textStyle=”bold”
android:layout_gravity=”center”
android:text=”@string/checkboxtext”
android:layout_marginBottom=”60dp” />

<CheckBox
android:layout_width=”100dp”
android:layout_height=”wrap_content”
android:id=”@+id/cb1″
android:layout_gravity=”center”
android:text=”C”
android:layout_marginBottom=”10dp”/>

<CheckBox
android:layout_width=”100dp”
android:layout_height=”wrap_content”
android:layout_gravity=”center”
android:id=”@+id/cb2″
android:text=”C++”
android:layout_marginBottom=”10dp” />

<CheckBox
android:layout_width=”100dp”
android:layout_height=”wrap_content”
android:id=”@+id/cb3″
android:layout_gravity=”center”
android:text=”Java”
android:layout_marginBottom=”20dp”/>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_gravity=”center”
android:textAppearance=”?
android:attr/textAppearanceLarge”
android:text=” “
android:id=”@+id/textView”
android:layout_marginBottom=”20dp” />

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Submit”
android:layout_gravity=”center”
android:onClick=”displayItems”
android:id=”@+id/button”
android:layout_marginBottom=”60dp”/>

<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/sourcecode”
android:background=”@color/bgcolor”
android:textStyle=”bold”
android:textColor=”@color/text”
android:onClick=”view1″/>

</LinearLayout>

 

Android Checkbox Example Output:

Android Checkbox source code download  Android Checkbox source code download

Android Checkbox source code download

Download CheckBox Source Code

For More Android Programs –Click Here

 

Follow Us – Never Miss Update

Fb/PageTwitterGoogle+InstagramPinterest

 

Related Search

Android Checkbox source code download, Android checkbox example code download, checkbox checked unchecked examples, checkbox android example source download, uncheck check source download android

Comments

10 Best Building Games on PC in 2024 Review: Why Buy Lava Blaze Curve 5G? Sale is Live! Review: Why Buy boAt Stone Spinx Pro? New Portable Speaker Xiaomi 14 Series Debuts in India, starting at ₹59,999 Best Wireless TWS Earbuds: Up to 75% Off Deals