Advertisement
SkolaRajakAndroid

MainActivity

Sep 3rd, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. import android.app.Activity;
  2. import android.os.Bundle;
  3. import android.view.View;
  4. import android.view.View.OnClickListener;
  5. import android.widget.Button;
  6. import android.widget.CheckBox;
  7. import android.widget.Toast;
  8.  
  9. public class MyAndroidAppActivity extends Activity {
  10.  
  11. ////////////////////////////////////////////////////////////
  12.   private CheckBox chkIos, chkAndroid, chkWindows;
  13.   private Button btnDisplay;
  14. /////////////////////////////////////////////////////
  15.  
  16.   @Override
  17.   public void onCreate(Bundle savedInstanceState) {
  18.     super.onCreate(savedInstanceState);
  19.     setContentView(R.layout.main);
  20. //////////////////////////////////////////////
  21.     addListenerOnChkIos();
  22.     addListenerOnButton();
  23. ////////////////////////////////////////////////////
  24.   }
  25.  
  26. ////////////////////////////////////////////////////////////////////////////
  27. public void addListenerOnChkIos() {
  28.  
  29.     chkIos = (CheckBox) findViewById(R.id.chkIos);
  30.  
  31.     chkIos.setOnClickListener(new OnClickListener() {
  32.  
  33.       @Override
  34.       public void onClick(View v) {
  35.                 //is chkIos checked?
  36.         if (((CheckBox) v).isChecked()) {
  37.             Toast.makeText(getApplicationContext(),
  38.                "Bro, try Android :)", Toast.LENGTH_LONG).show();
  39.         }
  40.  
  41.       }
  42.     });
  43.  
  44.   }
  45.  
  46.   public void addListenerOnButton() {
  47.  
  48.     chkIos = (CheckBox) findViewById(R.id.chkIos);
  49.     chkAndroid = (CheckBox) findViewById(R.id.chkAndroid);
  50.     chkWindows = (CheckBox) findViewById(R.id.chkWindows);
  51.     btnDisplay = (Button) findViewById(R.id.btnDisplay);
  52.  
  53.     btnDisplay.setOnClickListener(new OnClickListener() {
  54.  
  55.           //Run when button is clicked
  56.       @Override
  57.       public void onClick(View v) {
  58.  
  59.         StringBuffer result = new StringBuffer();
  60.         result.append("IPhone check : ").append(chkIos.isChecked());
  61.         result.append("\nAndroid check : ").append(chkAndroid.isChecked());
  62.         result.append("\nWindows Mobile check :").append(chkWindows.isChecked());
  63.  
  64.         Toast.makeText(getApplicationContext(), result.toString(),
  65.                 Toast.LENGTH_LONG).show();
  66.  
  67.       }
  68.     });
  69.  
  70.   }
  71. /////////////////////////////////////////////////////////////////////////////////////
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement