Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should be using an <code>onCheckedChangeListener</code> to properly listen for <code>CheckBox</code> changes. </p> <p>I rewrote your activity to implement these and properly set the <code>onClick</code> of your button.. Remove the onClick declarations in your XML file</p> <pre><code>public class MainActivity extends Activity implements OnCheckedChangeListener { private CheckBox chkAndroid, chkIphone, chkWindows; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); chkAndroid = (CheckBox) findViewById(R.id.checkBox_android); chkAndroid.setOnCheckedChangeListener(this); chkIphone = (CheckBox) findViewById(R.id.checkBox_ios); chkIphone.setOnCheckedChangeListener(this); chkWindows = (CheckBox) findViewById(R.id.checkBox_windows); chkWindows.setOnCheckedChangeListener(this); button = (Button) findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub StringBuffer string = new StringBuffer(); string.append("Iphone checked: ").append(chkIphone.isChecked()); string.append("\nAndroid checked: ").append(chkAndroid.isChecked()); string.append("\nWindows checked: ").append(chkWindows.isChecked()); Toast.makeText(getApplicationContext(), string.toString(), Toast.LENGTH_SHORT).show(); } }); } @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView == chkAndroid) { // do whatever.. you aren't doing anything currently } else if (buttonView == chkIphone &amp;&amp; isChecked) { displaySuggestion(); } else if (buttonView == chkWindows &amp;&amp; isChecked) { displaySuggestion(); } } private void displaySuggestion() { Toast.makeText(getApplicationContext(), "Try android", Toast.LENGTH_SHORT).show(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload