android - How to detect whether spinner item selected or not? -
normally spinner can item setonitemselected if user didn't click select @ all? how should edit code detect whether user click on spinner select item or not? can please advice me?
here's code:
s = (spinner) findviewbyid(r.id.rg); arrayadapter<charsequence> adapter = arrayadapter.createfromresource(this, r.array.gender_array, android.r.layout.simple_spinner_item); adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); s.setadapter(adapter); s.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> adapterview, view view, int i, long l) { gender = adapterview.getitematposition(i).tostring(); } @override public void onnothingselected(adapterview<?> adapterview) { toast.maketext(register.this, "please select gender", length_short).show(); return; } });
you can use
spinner.getselecteditem()
or
spinner.getselecteditemid() //return id of selected item (should override method"getitemid" in adapter class )
or
spinner.getselecteditemposition() //return position of selected item (index in adapter)
Comments
Post a Comment