Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- ToggleButton toggle;
- CheckBox cb;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ToggleButton toggle = (ToggleButton) findViewById(R.id.toggle1);
- toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (isChecked) {
- // The toggle is enabled
- Toast.makeText(getApplicationContext(),"Tombol ON", Toast.LENGTH_SHORT).show();
- } else {
- // The toggle is disabled\
- Toast.makeText(getApplicationContext(),"Tombol OFF", Toast.LENGTH_SHORT).show();
- }
- }
- });
- CheckBox cb = (CheckBox) findViewById(R.id.cb);
- cb.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- boolean checked = ((CheckBox) v).isChecked();
- // Check which checkbox was clicked
- if (checked) {
- // Do your coding
- Toast.makeText(getApplicationContext(), "Tombol CHECKED", Toast.LENGTH_SHORT).show();
- } else {
- Toast.makeText(getApplicationContext(), "Tombol UNCHECKED", Toast.LENGTH_SHORT).show();
- // Do your coding
- }
- }
- });
- final RadioButton rblaki, rbperempuan;
- rblaki = (RadioButton)findViewById(R.id.rb_1);
- rbperempuan = (RadioButton)findViewById(R.id.rb_2);
- Button btn = (Button)findViewById(R.id.btn1);
- btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- String result = (rblaki.isChecked())?"laki":(rbperempuan.isChecked())?"perempuan":"";
- Toast.makeText(getApplicationContext(), "Tombol Radio = " + result , Toast.LENGTH_SHORT).show();
- }
- });
- }
- public void tampil(View view){
- Toast.makeText(getApplicationContext(), "tombol ditekan", Toast.LENGTH_SHORT).show();
- }
- public void onRadioButtonClicked(View view) {
- boolean checked = ((RadioButton) view).isChecked();
- String str="";
- // Check which radio button was clicked
- switch(view.getId()) {
- case R.id.rb_1:
- if(checked)
- str = "laki";
- break;
- case R.id.rb_2:
- if(checked)
- str = "perempuan";
- break;
- }
- Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT).show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement