How Android directly based on the value selected by default, set the spinner:
Seeking common method
setSpinnerItemSelectedByValue
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
setSelection (int index)
index starts from 0.
Reply:
I do not know the value corresponding to the index
Reply:
Engage out:
/ **
* Based on the value set spinner selected by default:
* @ Param spinner
* @ Param value
* /
public static void setSpinnerItemSelectedByValue (Spinner spinner, String value) {
SpinnerAdapter apsAdapter = spinner.getAdapter (); / / get SpinnerAdapter object
int k = apsAdapter.getCount ();
for (int i = 0; iif (value.equals (apsAdapter.getItem (i). toString ())) {
spinner.setSelection (i, true) ;/ / default selected item
break;
}
}
}
Reply:
No comments:
Post a Comment