I am using the below code to select the last item of my list as hint of the spinner (ie. the default selected item in the spinner) and am trying to hide it from the dropdown menu.
List<String> rfpType = new ArrayList<>();
rfpType.add("Job");
rpType.add("Talent");
rfpType.add("Vendor");
rfpType.add("Sponsor");
rfpType.add("RFP Title");
HintAdapter dataAdapter1 = new HintAdapter(getActivity(), android.R.layout.simple_list_item_1, rfpType);
dataAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerRFPType.setAdapter(dataAdapter1);
spinnerRFPType.setSelection(dataAdapter1.getCount());
HintAdapter
class HintAdapter extends ArrayAdapter<String>{
public HintAdapter(Context context, int theLayoutResID , List<String> list){
super(context, theLayoutResID, list);
}
@Override
public int getCount() {
// don't display last item. It is used as hint.
int count = super.getCount();
return count > 0 ? count-1 : count;
}
}
But it displays the second last item as default. And hides the last item which I want to use as the hint. Suggest me a correct solution.