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方法中加入適配器?
謝謝
嘗試_data = data.clone添加這個(); – 2013-04-06 19:26:42
你有沒有使用ArrayAdapter而不是BaseAdapter的具體原因? – FoamyGuy 2013-04-06 19:28:32