java - Hide String Array Value in Spinner -
i using 2 spinners , populating both using same string array :
final string[] arraymonths = { "january", "feburary", "march", "april", "may", "june", "july", "august", "september", "october", "november","december" };
now make small change, don't want show december
in spinner1 , january
in spinner2.
so have make change in code done ?
code
adapter = new arrayadapter<string> (connectedspinnersstartend.this, android.r.layout.simple_spinner_item, arraymonths); spinner1.setadapter(adapter);
it's easier think. first step moving array arraylist, gives more flexibility, , submit arrayadapter
instead of array
arraylist<string> mlist = new arraylist( arrays.aslist(arraymonths)); mlist.remove("december"); adapter = new arrayadapter<string> (connectedspinnersstartend.this, android.r.layout.simple_spinner_item, mlist);
on onitemselected
, if understand correctly, want remove selected item first spinner , add second's one,
spinner1.setonitemselectedlistener(new onitemselectedlistener() { @override public void onitemselected(adapterview<?> parent, view view, int position, long id) { string str1 = (string) parent.getitematposition(position); if (spinner2.getadapter() == null) { arraylist<string> list = new arraylist( arrays.aslist(arraymonths)); list.remove("january"); arrayadapter adapter = new arrayadapter<string>(connectedspinnersstartend.this, android.r.layout.simple_spinner_item, list); spinner2.setadapter(adapter); }
i wrote on top of head, check typo
Comments
Post a Comment