Как заполнить ListView с помощью пользовательского адаптера? вид списка пустой (

У меня есть собственный адаптер для просмотра списка. Программа работает без ошибок, НО просмотр списка пустой.

Мой адаптер выглядит так:

public class CustomAdapter extends BaseAdapter implements Filterable {

private ArrayList<OItem> _data;
Context _c;

public CustomAdapter(ArrayList<OItem> data, Context c) {
    _data = data;
    _c = c;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null)
    {
       LayoutInflater vi = (LayoutInflater)_c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       v = vi.inflate(R.layout.item, null);
    }

    OItem oItem = _data.get(position);

    TextView tvId = (TextView)v.findViewById(R.id.id);
    TextView tvName = (TextView)v.findViewById(R.id.name);
    TextView tvBatch = (TextView)v.findViewById(R.id.batch);

    tvId.setText(oItem.getId());
    tvName.setText(oItem.getName());
    tvBatch.setText(oItem.getBatch());

   return v;
}
}

В действии:

ArrayList<OItem> arrItems = new ArrayList<OItem>();
....
here I fill arrItens with the data
....
ListView lvSimple = (ListView) findViewById(R.id.lvContent);
lvSimple.setAdapter(new CustomAdapter(arrItems, this));

В чем может быть проблема? Может стоит что-то добавить в методе getView адаптера?

Спасибо


person Pavel Zdarov    schedule 06.04.2013    source источник
comment
попробуйте _data = data.clone();   -  person Hoan Nguyen    schedule 06.04.2013
comment
у вас есть конкретная причина не использовать ArrayAdapter вместо BaseAdapter?   -  person FoamyGuy    schedule 06.04.2013


Ответы (1)


я предполагаю, что вы не реализовали getCount, добавьте это в свой CustomAdapter

   public int getCount() {
    return null == _data ? 0 : _data.size();
}
person Akhil    schedule 06.04.2013
comment
Спасибо) мой getCount был пуст - person Pavel Zdarov; 06.04.2013