1

I have Alert Dialog with multiplechoiceItems. In which some are already checked values according to parsing. I want that values which are already checked, should not be unchecked.Please help me if any 1 have any idea.

Riddhi Barbhaya
  • 1,205
  • 1
  • 11
  • 19

3 Answers3

3

Make them disable which are already checked

Harish Godara
  • 2,388
  • 1
  • 14
  • 28
  • Actually checked values are coming form server and even i don't know the values which are checked. so How can I make them disable? I am getting values dynamically. – Riddhi Barbhaya Aug 05 '13 at 11:44
  • Suppose you are having 10 ckeckboxes and out of them seven are checked, then you have to do 1 thing, when you are setting them checked according server values at that point of time make them disable also. – Harish Godara Aug 05 '13 at 11:55
  • 1
    Please check this if you have multichoiceitems : http://stackoverflow.com/questions/2183610/android-how-to-disable-list-items-on-list-creation – Harish Godara Aug 05 '13 at 12:07
0

Your question isn't too clear, but something like this might work:

yourCheckboxID.setOnCheckedChangeListener(new OnCheckedChangeListener(){
    @Override
    public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {  
        if (isChecked){
        yourCheckboxID.setEnabled(false);
        }
    }
});

or you may need:

if(yourCheckboxID.isChecked()){
   yourCheckboxID.setEnabled(false);
}

Let me know if that's what you were after!

Joe Birch
  • 371
  • 2
  • 7
  • Actually its not checkbox but its AlertDialog with multichoiceItems. Sorry I mentioned wrong in Question, now I edited it. – Riddhi Barbhaya Aug 05 '13 at 11:48
  • 1
    OK well, use an OnMultiChoiceClickListener(), see [link]http://stackoverflow.com/questions/3608018/toggling-check-boxes-in-multichoice-alertdialog-in-android[/link] – Joe Birch Aug 05 '13 at 11:54
0

When a Checkbox is checked/unchecked you can handle in an event called OnCheckedChangedListener

For example:

CheckBox cb;
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    //In case that the new isChecked is false, you let it true again
    if(!isChecked)
        buttonView.setChecked(true);
    }
});
Renan Bandeira
  • 3,238
  • 17
  • 27