Pav*_*rov 0 android listview custom-adapter
我有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;
}
}
Run Code Online (Sandbox Code Playgroud)
在活动中:
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));
Run Code Online (Sandbox Code Playgroud)
可能是什么问题?也许应该在适配器的getView方法中添加一些东西?
谢谢
我假设您没有实现getCount,请在CustomAdapter中添加它
public int getCount() {
return null == _data ? 0 : _data.size();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1172 次 |
| 最近记录: |