Advertisement
apl-mhd

checkbox click

Jan 18th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package com.example.reaz.cheackbox;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.CheckBox;
  8. import android.widget.Toast;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11.  
  12.  private    CheckBox check1, check2, check3;
  13.   private   Button button;
  14.  
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.activity_main);
  19.  
  20.         setOnButtonClick();
  21.     }
  22.  
  23.  
  24.     public void setOnButtonClick(){
  25.  
  26.         check1 =(CheckBox)findViewById(R.id.checkBox);
  27.         check2 =(CheckBox)findViewById(R.id.checkBox2);
  28.         check3 =(CheckBox)findViewById(R.id.checkBox3);
  29.         button =(Button)findViewById(R.id.button);
  30.  
  31.         button.setOnClickListener(new View.OnClickListener() {
  32.             @Override
  33.             public void onClick(View v) {
  34.                 StringBuffer str = new StringBuffer();
  35.                 str.append("Dog ").append(check1.isChecked()+"\n");
  36.                 str.append("Cat ").append(check1.isChecked()+"\n");
  37.                 str.append("Cow ").append(check1.isChecked()+"\n");
  38.  
  39.                 Toast.makeText(MainActivity.this, str, Toast.LENGTH_SHORT).show();
  40.             }
  41.         });
  42.  
  43.  
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement