csdn用户R 2015-01-12 07:03 采纳率: 100%
浏览 4501
已采纳

给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条回答 默认 最新

  • q107770540 2015-01-12 07:07
    关注

    先自己debug后找找问题

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题