我正在使用以下代碼來選擇列表中的最後一項作爲微調控件的提示(即微調控件中的默認選定項目)並試圖從下拉菜單中隱藏它。在Spinner(默認項目)中使用項目作爲提示並將其隱藏在下拉列表中
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;
}
}
但它顯示的倒數第二項爲默認值。並隱藏我想用作提示的最後一個項目。建議我一個正確的解決方案。
變化spinnerRFPType.setSelection(dataAdapter1.getCount() - 1); spinnerRFPType.setSelection(dataAdapter1.getCount()); – Nisarg
嘿它根據期望工作..我寫了相同的代碼,如上所述沒有change.check屏幕截圖.https://postimg.org/image/x15zi375j/ 和這一個 https://postimg.org/image/ jyacytgxj/ –
@ShakeebAyaz我也認爲它應該工作。但不幸的是它沒有。任何想法如何糾正? – h8pathak