【发布时间】:2019-05-14 13:28:09
【问题描述】:
如何设置微调器列表第一个位置值显示为空,我附加了适配器和活动:请解决我的问题。
SpinnerAdapterIdtypeMaster
public class SpinnerAdapterIdtypeMaster extends ArrayAdapter {
private Context mContext;
private List<CMSSubMasterDB> spinnerList = new ArrayList<>();
private MasterType type;
public SpinnerAdapterIdtypeMaster(@NonNull Context context, List<CMSSubMasterDB> list) {
super(context, 0, list);
mContext = context;
spinnerList = list;
}
@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
@Override
public int getCount() {
return spinnerList.size();
}
@Nullable
@Override
public CMSSubMasterDB getItem(int position) {
return spinnerList.get(position);
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View listItem = convertView;
if (listItem == null)
listItem = LayoutInflater.from(mContext).inflate(R.layout.spinner_list, parent, false);
CMSSubMasterDB currentMovie = spinnerList.get(position);
TextView name = (TextView) listItem.findViewById(R.id.spinner);
name.setText(currentMovie.name);
return listItem;
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//return super.getView(position, convertView, parent);
View listItem = convertView;
if (listItem == null)
listItem = LayoutInflater.from(mContext).inflate(R.layout.spinner_list, parent, false);
TextView label = (TextView) listItem.findViewById(R.id.spinner);
label.setText(spinnerList.get(position).name);
return listItem;
}
}
创建RyotManagerFragment
public class CreateRyotManagerFragment extends Fragment {
Spinner mIDType
List<CMSSubMasterDB> mIdtypeMasterList;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.layout_new_ryot, container, false);
mIDType = view.findViewById(R.id.idtype);
mIdtypeMasterList = AppUtils.getIDTypeMasterDb();
SpinnerAdapterIdtypeMaster idTypeMaster = new SpinnerAdapterIdtypeMaster(getActivity().getApplicationContext(), mIdtypeMasterList);
mIDType.setAdapter(idTypeMaster);
return view;
}
}
【问题讨论】:
-
你的第一个位置设置为空?
-
是的,我想要空的或任何提示