我正在创建多选微调器,并且“全部清除”按钮出现问题 http://postimg.org/image/eoyq5jpib/但“全选”工作相当不错,但点击“全部清除”时没有任何反应。为什么我会遇到“全部清除”的问题?
protected CharSequence[] _options = { "One", "Two", "Three", "Four", "Five" };
protected boolean[] _selections = new boolean[ _options.length ];
protected Button _optionsButton;
public class ButtonClickHandler implements View.OnClickListener {
public void onClick( View view ) {
showDialog( 0 );
}
}
@Override
protected Dialog onCreateDialog( int id )
{
return
new AlertDialog.Builder( this )
.setTitle( "Students" )
.setMultiChoiceItems(_options, _selections, new DialogSelectionClickHandler())
.setPositiveButton("OK", new DialogButtonClickHandler())
.setNeutralButton("Select All",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
selectAllStudents();
}
})
.setNegativeButton("Clear All",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
clearAllStudents();
}
})
.create();
}
public class DialogSelectionClickHandler implements DialogInterface.OnMultiChoiceClickListener
{
public void onClick( DialogInterface dialog, int clicked, boolean selected )
{
Log.i("ME", _options[clicked] + " selected: " + selected);
}
}
public class DialogButtonClickHandler implements DialogInterface.OnClickListener
{
public void onClick( DialogInterface dialog, int clicked )
{
checkAllStudents();
switch( clicked )
{
case DialogInterface.BUTTON_POSITIVE:
printSelectedStudents();
break;
case DialogInterface.BUTTON_NEUTRAL:
printSelectedStudents();
break;
case DialogInterface.BUTTON_NEGATIVE:
printSelectedStudents();
break;
}
}
}
protected void clearAllStudents(){
for (int i = 0; i<_options.length; i++) {
_selections[i] = false;
}
}
protected void selectAllStudents(){
for (int i = 0; i<_options.length; i++) {
_selections[i] = true;
}
}
protected void printSelectedStudents(){
for( int i = 0; i < _options.length; i++ ){
Log.i( "ME", _options[ i ] + " selected: " + _selections[i] );