1

I want to create custom spinner and this is 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;
}

and implement in 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);

the result is getDropDownView us called , but getView never called .

so how to fix it ?

Amay Diam
  • 2,561
  • 7
  • 33
  • 57

0 Answers0