2011-02-17 56 views
0
protected CharSequence[] _options = { "English ", "Thai", "German", "Italy", "Spain", "All languages" }; 
protected boolean[] _selections = new boolean[ _options.length ]; 
@Override 
protected Dialog onCreateDialog(int id) 
{ 
    return 
    new AlertDialog.Builder(this) 
     .setTitle("Choose Language") 
     .setMultiChoiceItems(_options, _selections, new DialogSelectionClickHandler()) 
     .setPositiveButton("OK", new DialogButtonClickHandler()) 
     .create(); 
} 

public class DialogSelectionClickHandler implements DialogInterface.OnMultiChoiceClickListener 
{ 
    @Override 
    public void onClick(DialogInterface dialog, int clicked, boolean selected) 
    { 
     Log.i("ME", _options[ clicked ] + " selected: " + selected); 
    } 
} 

public class DialogButtonClickHandler implements DialogInterface.OnClickListener 
{ 
    @Override 
    public void onClick(DialogInterface dialog, int clicked) 
    { 
     switch(clicked) 
     { 
      case DialogInterface.BUTTON_POSITIVE: 

       printSelectedLanguage(); 
       break; 
     } 
    } 
} 
protected void printSelectedLanguage(){ 
    for(int i = 0; i < _options.length; i++){ 
     Log.i("ME", _options[ i ] + " selected: " + _selections[i]); 
    } 
} 

我怎么能检查哪些复选框被选中关于复选框

回答

1
final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id); 
     if (checkBox.isChecked()) { 
      // action 
     } 

使用非标准的复选框方法。 顺便说一句,我没有看到任何代码