Pavel Zdarov
Pavel Zdarov

Reputation: 2347

How to fill ListView with the Custom Adapter? list view empty (

I have custom adapter for listview. Programm works without erros, BUT List view is empty.

My adapter looks like:

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;
}
}

In Activity:

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));

What can be the problem? Maybe something should be added in getView method of adapter?

Thank you

Upvotes: 0

Views: 1211

Answers (1)

Akhil
Akhil

Reputation: 6697

i assume you have not implemented getCount, add this in your CustomAdapter

   public int getCount() {
    return null == _data ? 0 : _data.size();
}

Upvotes: 4

Related Questions