disable spinner based another spinner android -
how disable spinner based on spinner. sample, when choose first spinner value "yes" second spinner enable when choose first spinner value "no" second spinner disable.
thanks
try this:
final spinner sp1 = (spinner) findviewbyid(r.id.spinner1); final spinner sp2 = (spinner) findviewbyid(r.id.spinner2); arrayadapter<string> data = new arrayadapter<string>(this, android.r.layout.simple_dropdown_item_1line, first); arrayadapter<string> data2 = new arrayadapter<string>(this, android.r.layout.simple_dropdown_item_1line, second); sp1.setadapter(data); sp2.setadapter(data2); sp1.setonitemselectedlistener(new onitemselectedlistener() { @override public void onitemselected(adapterview<?> parent, view view, int position, long id) { string text = sp1.getselecteditem().tostring(); if (text.equals("no")) { sp2.setenabled(false); } else { sp2.setenabled(true); } } @override public void onnothingselected(adapterview<?> arg0) { // todo auto-generated method stub } });
Comments
Post a Comment