multi select spinner clearAll button android -
i'm creating multi select spinner , got problem clear button http://postimg.org/image/eoyq5jpib/ "select all" work pretty when clicked on "clear all" nothing happens. why i'm getting problem "clear all"?
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( ) .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(){ (int = 0; i<_options.length; i++) { _selections[i] = false; } } protected void selectallstudents(){ (int = 0; i<_options.length; i++) { _selections[i] = true; } } protected void printselectedstudents(){ for( int = 0; < _options.length; i++ ){ log.i( "me", _options[ ] + " selected: " + _selections[i] );
Comments
Post a Comment