Friday, 18 January 2013

ChekBox Demo

Screen Shots:



1.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:background="#ffffff"
    android:orientation="vertical" >

    <CheckBox
        android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:text="Chekbox"
        android:textColor="#000000" />

    <Button
        android:id="@+id/btnShow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:text="Show" />

</LinearLayout>




2.Activity:

package com.venkool.checkbox;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

public class CheckBoxDemoActivity extends Activity {
      /** Called when the activity is first created. */

      Button btnShow;

      CheckBox checkbox;

      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            checkbox = (CheckBox) findViewById(R.id.checkbox);

            btnShow = (Button) findViewById(R.id.btnShow);
            btnShow.setOnClickListener(new OnClickListener() {

                  public void onClick(View v) {
                        // TODO Auto-generated method stub

                        if (checkbox.isChecked()) {
                              Toast.makeText(getApplicationContext(), "Checked", 5000)
                                          .show();
                        } else {
                              Toast.makeText(getApplicationContext(), "UnChecked", 5000)
                                          .show();
                        }
                  }
            });
      }
}



3)Download this Project Click Here

 

No comments:

Post a Comment