Thursday, July 5, 2012

CheckBox In Android



Click Here To Downloan Source Code.


package name : selva.checkbox

project name  :  CheckBox

version           :  1.5 ( Support 1.5 and above versions)


main.xml



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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="84dp"
        android:text="Check Box"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#00ff00" />

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox 1" />

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox 2" />

    <CheckBox
        android:id="@+id/checkBox3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox 3" />
   
</LinearLayout>







 CheckBoxActivity.java

  


package selva.checkbox;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class CheckBoxActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        CheckBox cbox1=(CheckBox) findViewById(R.id.checkBox1);
        CheckBox cbox2=(CheckBox) findViewById(R.id.checkBox2);
        CheckBox cbox3=(CheckBox) findViewById(R.id.checkBox3);
      
       
        cbox1.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                if ( isChecked )
                {
                  
                   Toast.makeText(getApplicationContext(), "Checkbox 1 is checked", Toast.LENGTH_SHORT).show();
                  
                }
                else
                {
                   Toast.makeText(getApplicationContext(), "Checkbox 1 is Unchecked", Toast.LENGTH_SHORT).show();
                }
              
              
              
              
            }});
       
       
        cbox2.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                if ( isChecked )
                {
                  
                   Toast.makeText(getApplicationContext(), "Checkbox 2 is checked", Toast.LENGTH_SHORT).show();
                  
                }
                else
                {
                   Toast.makeText(getApplicationContext(), "Checkbox 2 is Unchecked", Toast.LENGTH_SHORT).show();
                }
              
              
              
              
            }});
       
       
       
        cbox3.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                if ( isChecked )
                {
                  
                   Toast.makeText(getApplicationContext(), "Checkbox 3 is checked", Toast.LENGTH_SHORT).show();
                  
                }
                else
                {
                   Toast.makeText(getApplicationContext(), "Checkbox 3 is Unchecked", Toast.LENGTH_SHORT).show();
                }
              
          
              
            }});

    }


OUTPUT:






































Click CheckBox 1












































Click CheckBox 1










































Click Here To Downloan Source Code.


No comments:

Post a Comment