关于复选框

时间:2011-02-17 09:42:48

标签: android checkbox

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] );
    }
}

如何检查选中了哪个复选框

2 个答案:

答案 0 :(得分:1)

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

使用标准复选框方法。 顺便说一下,我在代码中看不到任何内容

答案 1 :(得分:0)

尝试this