android - How to enable button after using spinner -
i creating program has mainmenubutton button (created in oncreate) disabled default. user first has check few boxes , select spinner before mainmenubutton button becomes enabled. currently, can't button enable after using spinner.
i've tried both
@override public void onclick(view v) { switch(v.getid()) { case r.id.main_menu_button: openmainmenu(); break; case r.id.building_spinner: button mainmenubutton=(button)findviewbyid(r.id.main_menu_button); mainmenubutton.setenabled(true); break; } }
and
public void onitemselected(adapterview<?> parent, view view, int position, long id) { view mainmenubutton=(view)findviewbyid(r.id.main_menu_button); mainmenubutton.setenabled(true); }
but no avail. i've tried replacing view
button
, didn't enable mainmenubutton either. supposed enable button after on spinner has been selected?
also, there of big difference implement checkboxes well?
edit2 :
if comment out if , else statement, button remains permanently disabled. if leave is, button never disabled begin , never disables, don't understand because haven't touched spinner, should disabled default.
public void onitemselected(adapterview<?> parent, view view, int position, long id) { string buildingstring = parent.getitematposition(position).tostring(); if(buildingstring !="select building") { button mainmenubutton=(button)findviewbyid(r.id.main_menu_button); mainmenubutton.setenabled(true); } else { button mainmenubutton=(button)findviewbyid(r.id.main_menu_button); mainmenubutton.setenabled(false); } }
im not sure if affects it, spinner strings formatted :
<string-array name="building_array"> <item>select building</item>
you've not registered listener on spinner.
add in oncreate
spinner.setonitemselectedlistener(this);
and write code in onitemselected.
Comments
Post a Comment