Reputation: 3131
I am using a SpinnerAdpter for my spinner but I don't know how to set a selection in code. the answers I've found are not using a SpinnerAdapter so their solution did not work for me.
here is my adapter:
private class PackPricesAdapter extends BaseAdapter implements SpinnerAdapter {
@Override
public int getCount() {
return spinnerPackPrices.size();
}
@Override
public Object getItem(int position) {
return spinnerPackPrices.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
TextView text = new TextView(mContext);
text.setText(spinnerPackPrices.get(position));
text.setTextSize(13f);
return text;
}
}
I wanna know how I can set a selection programmatically.
Upvotes: 1
Views: 543
Reputation: 6892
To set a selection on your Spinner
, after setting the adapter to it, just call:
spinner.setSelection(position);
Where position
is the 0-based position of the Spinner item you want to select.
Upvotes: 1