我想创建自定义微调器,这是CustomSpinnerAdapter:
@Override
public int getCount() {
// TODO Auto-generated method stub
return (data == null) ? 0 : data.size();
}
@Override
public long getItemId (int position) {
return position;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
View row = inflater.inflate(R.layout.spinner_item_ip, parent, false);
TextView ip = (TextView) row.findViewById(R.id.ip);
ip.setText(data.get(position).toString());
return row;
}
并在Fragment中实现
List<String> dataIpList = new ArrayList<String>();
dataIpList.add("192.168.1.1");
dataIpList.add("192.168.1.2");
dataIpList.add("192.168.1.3");
dataIpList.add("192.168.1.4");
_spinnerIpAdapter = new spinnerIpAdapter(getActivity(), R.layout.spinner_item_ip, dataIpList);
publicIP.setAdapter(_spinnerIpAdapter);
结果是我们调用了getDropDownView,但getView从未调用过。
那么如何解决呢?