3
I wish that couldn’t happen.
The user clicking on the other CheckBox
, disable the one previously marked.
Mainactivity.java
package genesysgeneration.umouoto;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
public class MainActivity extends AppCompatActivity {
private CheckBox cb01, cb02;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cb01=(CheckBox)findViewById(R.id.cb01);
cb02=(CheckBox)findViewById(R.id.cb02);
addCheckBoxChecked();
}
public void addCheckBoxChecked(){
cb01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(((CheckBox)v).isChecked()){
}
}
});
cb02.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
It is not easier to use radiobutton no?
– user28595
I thought about it and would put in an observation on the question. No, it does not suit me.
– Boneco Sinforoso
Because the radio button doesn’t fit?
– viana
I believe that the radiobutton can work with clusters (doubles, triples), but I intend to create activitys in which the conditions are not so simple, things that are not necessarily contrary, opposite, exclusionary. There will be cases where the user has to select for example 6 of 8 items.
– Boneco Sinforoso
But nothing prevents this case in specific implement radiobutton. And from what I can see, you will have to work with cross listeners between the two checkboxes to handle this, see this answer in Soen:http://stackoverflow.com/a/13133373/5524514
– user28595