2013-04-06 68 views
0

我有自定义适配器列表视图PROGRAMM工作没有错误回报,但列表视图是空如何使用自定义适配器填充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方法中加入适配器?

谢谢

+0

尝试_data = data.clone添加这个(); – 2013-04-06 19:26:42

+0

你有没有使用ArrayAdapter而不是BaseAdapter的具体原因? – FoamyGuy 2013-04-06 19:28:32

回答

5

我想你还没有实现getCount将在您的CustomAdapter

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

谢谢)我的getCount是空的 – 2013-04-06 19:33:39

相关问题