未调用getView Custom Spinner Android?

时间:2015-07-21 10:08:11

标签: java android

我想创建自定义微调器,这是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从未调用过。

那么如何解决呢?

0 个答案:

没有答案