列表视图的内容不会出现

时间:2012-05-18 11:33:19

标签: android listview adapter

我的代码运行没有错误,但自定义Listview不显示值。

我的代码运行没有错误,但自定义Listview不显示值。

这是我的代码:

适配器

public class Adapter扩展BaseAdapter {

 ArrayList<mealItems> itemList;

public Activity context;
public LayoutInflater inflater;


public DiseasesAdapter(Activity context,int x,ArrayList<mealItems> itemList) {
    super();

    this.context = context;
    this.itemList = itemList;
    this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}


public Object getItem(int position) {

    return itemList.get(position);
}

public long getItemId(int position) {

    return 0;
}

public static class ViewHolder
{
    ImageView img;
    TextView Title;

}


public View getView(int position, View convertView, ViewGroup parent) {


    ViewHolder holder;
    if(convertView==null)
    {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.disease_row, null);

        holder.Title = (TextView) convertView.findViewById(R.id.Name);
        holder.img = (ImageView) convertView.findViewById(R.id.image);
        convertView.setTag(holder);
    }
    else
        holder=(ViewHolder)convertView.getTag();

    Items bean = (Items) itemList.get(position);
    holder.Title.setText(bean.getTitle());
    holder.img.setImageResource(bean.getImage());


    return convertView;
}

public int getCount() {
    // TODO Auto-generated method stub
    return 0;
}

}

2 个答案:

答案 0 :(得分:2)

您的getCount()方法返回0,这应该返回itemList的大小。

return itemList.size()

答案 1 :(得分:0)

试试这个:

this.itemList=new ArrayList<mealItems>();
this.itemList.addAll(itemList);

当然,getCount()方法返回itemList.size()