Android > CheckBox

May 19, 2012   ·   0 Comments

Screen Shot 2012-05-19 at 10.36.18 AM

source code:Tutorial_UI_CheckBox

package com.powenko.Tutorial_UI_CheckBox;

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

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

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

   	     checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
   	     
   	  
   	  checkBox1.setOnClickListener(new OnClickListener() {
   
  	  @Override
  	  public void onClick(View v) {
                  //is chkIos checked?
  		if (((CheckBox) v).isChecked()) {
  			Toast.makeText(Tutorial_UI_CheckBoxActivity.this,
  		 	   "powenko.com click)", Toast.LENGTH_LONG).show();
  		}else{

  			Toast.makeText(Tutorial_UI_CheckBoxActivity.this,
  		 	   "powenko.com unclick)", Toast.LENGTH_LONG).show();
  		}
   
  	  }
  	});
    }
}

layout

<?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:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

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

</LinearLayout>
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon