给GridView写的adapter不显示数据,几个人都说没问题

gvGoods=(GridView) findViewById(R.id.gv_goods);
context=this;
ArrayList> data=new ArrayList>();
HashMap map1=new HashMap();
map1.put("image",R.drawable.bear);
map1.put("name", "熊");
map1.put("integral", 123);
map1.put("if", 1);
data.add(map1);
HashMap map2=new HashMap();
map2.put("image",R.drawable.bear);
map2.put("name", "熊张");
map2.put("integral", 231);
map2.put("if", 1);
data.add(map2);
HashMap map3=new HashMap();
map3.put("image",R.drawable.bear);
map3.put("name", "熊头");
map3.put("integral", 155);
map3.put("if", 1);
data.add(map3);
HashMap map4=new HashMap();
map4.put("image",R.drawable.bear);
map4.put("name", "熊头");
map4.put("integral", 155);
map4.put("if", 1);
data.add(map4);
HashMap map5=new HashMap();
map5.put("image",R.drawable.bear);
map5.put("name", "熊头");
map5.put("integral", 155);
map5.put("if", 2);
data.add(map5);
HashMap map6=new HashMap();
map6.put("image",R.drawable.bear);
map6.put("name", "熊头");
map6.put("integral", 155);
map6.put("if", 1);
data.add(map6);
HashMap map7=new HashMap();
map7.put("image",R.drawable.bear);
map7.put("name", "熊头");
map7.put("integral", 155);
map7.put("if", 1);
data.add(map7);
// SimpleAdapter mAdapter=new SimpleAdapter(context, list, R.layout.activity_exchange_items,
// new String[]{"image","name","integral"}, new int[]{R.id.iv_item_image,R.id.tv_item_name,R.id.tv_item_integral});
adapter=new ExchangeAdapter(context, data);
gvGoods.setAdapter(adapter);

    addListener();

///////上面是activity的参数和传递
、、、、、xia下面是adapter yemian页面不显示啊

package com.rockstar.shengong007.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import com.worker.app.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ExchangeAdapter extends BaseAdapter{
Context context;
ArrayList> list;
public ExchangeAdapter(Context context,ArrayList> data){
this.context=context;
if(list==null){
list=new ArrayList>();
}else{
this.list=data;
}
Log.i("ExchangeAdapter.log", list.toString());
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return list.get(position);
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    viewHolder viewholder;
    if(convertView==null){
        viewholder=new viewHolder();
        convertView=View.inflate(context, R.layout.activity_exchange_items, null);
        viewholder.ivImage=(ImageView) convertView.findViewById(R.id.iv_item_image);
        viewholder.tvName=(TextView) convertView.findViewById(R.id.tv_item_name);
        viewholder.tvIntegral=(TextView) convertView.findViewById(R.id.tv_item_integral);
        viewholder.llGone=(LinearLayout) convertView.findViewById(R.id.ll_gone_show);
        convertView.setTag(viewholder);
    }else{
        viewholder=(viewHolder) convertView.getTag();
    }
    HashMap<String, Object> map=list.get(position);
    viewholder.ivImage.setImageDrawable((Drawable) map.get("imaeg"));
    viewholder.tvName.setText((CharSequence) map.get("name"));
    viewholder.tvIntegral.setText((CharSequence) map.get("integral"));
    int i=(Integer) map.get("if");
    if(i==2){
        viewholder.llGone.setVisibility(View.VISIBLE);
    }
    return convertView;
}

private class viewHolder{
    private ImageView ivImage;
    private TextView tvName,tvIntegral;
    private LinearLayout llGone;
}

}

2个回答

先自己debug后找找问题

难道你们"几个人"中都没有一个会调试的?逐行运行找出程序的错误?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问