01 | package com.example.wenchen.myapplication; |
03 | import android.app.Activity; |
04 | import android.os.Bundle; |
05 | import android.view.View; |
06 | import android.view.View.OnClickListener; |
07 | import android.widget.Button; |
08 | import android.widget.CheckBox; |
09 | import android.widget.Toast; |
11 | public class MainActivity extends Activity { |
12 | private CheckBox chkIos, chkAndroid, chkWindows; |
13 | private Button btnDisplay; |
16 | public void onCreate( Bundle savedInstanceState ) { |
17 | super .onCreate( savedInstanceState ); |
18 | setContentView( R.layout.activity_main ); |
19 | addListenerOnChkIos( ); |
20 | addListenerOnButton( ); |
23 | public void addListenerOnChkIos( ) { |
24 | chkIos = (CheckBox) findViewById( R.id.chkIos ); |
25 | chkIos.setOnClickListener( new OnClickListener( ) { |
27 | public void onClick( View v ) { |
29 | if ( ((CheckBox) v).isChecked( ) ) { |
30 | Toast.makeText( MainActivity. this , |
31 | "Bro, try Android :)" , Toast.LENGTH_LONG ).show( ); |
37 | public void addListenerOnButton( ) { |
38 | chkIos = (CheckBox) findViewById( R.id.chkIos ); |
39 | chkAndroid = (CheckBox) findViewById( R.id.chkAndroid ); |
40 | chkWindows = (CheckBox) findViewById( R.id.chkWindows ); |
41 | btnDisplay = (Button) findViewById( R.id.btnDisplay ); |
42 | btnDisplay.setOnClickListener( new OnClickListener( ) { |
45 | public void onClick( View v ) { |
46 | StringBuffer result = new StringBuffer( ); |
47 | result.append( "iPhone check: " ).append( chkIos.isChecked( ) ); |
48 | result.append( "\nAndroid check: " ).append( chkAndroid.isChecked( ) ); |
49 | result.append( "\nWindows Phone check: " ).append( chkWindows.isChecked( ) ); |
50 | Toast.makeText( MainActivity. this , result.toString( ), |
51 | Toast.LENGTH_LONG ).show( ); |
|