我正在从hashmap的arraylist中显示列表。我创建了自己的适配器来显示该列表。但是我不能在列表中显示它。我甚至不能在那个适配器中进行调试。我的代码是这样的。
public class ListAdapter extends BaseAdapter {
Context _context;
ArrayList<HashMap<String, String>> lists = new ArrayList<HashMap<String, String>>();
public LayoutInflater myInflater;
public ListAdapter(Context context,ArrayList<HashMap<String, String>> list){
this._context = context;
this.lists = list;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
this.myInflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView==null)
{
convertView = myInflater.inflate(R.layout.list_items, parent, false);
TextView TT = (TextView) convertView.findViewById(R.id.system_text);
System.out.println("systemName name is"+this.lists.get(position).get("SystemName"));
TT.setText(this.lists.get(position).get("SystemName"));
}
return convertView;
}
}谢谢。
发布于 2014-01-19 14:14:58
您需要返回要显示的列表的大小
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}检查this for implementing the ListView with Custom BaseAdapter
检查此ViewHolder Pattern
发布于 2014-01-19 14:17:08
您将从getCount()方法返回0,这意味着您的ListView没有任何项。请对此进行更正,以返回列表中的项目数。
@Override
public int getCount() {
// TODO Auto-generated method stub
return items.size(); // HERE
}希望这能有所帮助。
发布于 2014-01-19 14:21:39
替换
convertView = myInflater.inflate(R.layout.list_items, parent, false);通过
convertView = myInflater.inflate(R.layout.list_items, null);示例:
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
return mInflater.inflate(view, null);https://stackoverflow.com/questions/21213804
复制相似问题