praew_z
praew_z

Reputation: 175

About check box

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

How can I check that which checkbox is checked

Upvotes: 0

Views: 158

Answers (2)

Michael
Michael

Reputation: 54705

Try this.

Upvotes: 0

Vivienne Fosh
Vivienne Fosh

Reputation: 1778

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

Using standart checkbox method. By the way i don't see any in the code

Upvotes: 1

Related Questions