2 qq 30562993 qq_30562993 于 2016.04.01 11:28 提问

listview 只显示最后一条数据,帮忙看看吧

图片说明

9个回答

cyxevil
cyxevil   2016.04.01 14:15
已采纳

package com.bypro.adapter.visit;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.bypro.R;
import com.bypro.activity.MainActivity;
import com.bypro.activity.visit.RecentVisitActivity;
import com.bypro.entity.ReMenEntityBrowse;
import com.bypro.entity.ReMenEntityBrowse.Type;

/**

  • */
    public class RoomListVisitAdapter extends BaseAdapter {

    private List arrayList;// 房源
    private Context context;
    private LayoutInflater inflater;
    private boolean flag;
    private List checkBoxs = new ArrayList();
    public SparseArray checkMap;
    public ArrayList positions;
    private List views = new ArrayList();
    private List datas = new ArrayList();
    private EditType mType = EditType.NO_EDIT;

    public enum EditType {
    EDIT, NO_EDIT
    }

    public EditType getmType() {
    return mType;
    }

    public void setmType(EditType mType) {
    this.mType = mType;
    }

    public RoomListVisitAdapter(Context context,
    List arrayList2) {
    this.arrayList = arrayList2;
    this.context = context;
    this.inflater = LayoutInflater.from(context);
    checkMap = new SparseArray();
    positions = new ArrayList();
    }

    @Override
    public int getCount() {
    return arrayList.size();
    }

    @Override
    public ReMenEntityBrowse getItem(int position) {
    return arrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
    return position;
    }

    ViewHolder vh = null;
    ViewHolder2 vh2 = null;
    Data data = new Data();

    class ClickListener implements OnClickListener {

    private int position;
    
    public ClickListener(int pos) {
        position = pos;
    }
    
    @Override
    public void onClick(View v) {
        CheckBox cb = (CheckBox) v.findViewById(R.id.room_img_check);
        if (cb.isChecked()) {
            cb.setChecked(false);
        } else {
            cb.setChecked(true);
        }
        notifyActivity(position, cb);
    }
    

    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    ReMenEntityBrowse entity = arrayList.get(position);

    if (convertView == null) {
        if (getItemViewType(position) == 0) {
            convertView = inflater.inflate(
                    R.layout.browse_item_room_new_view, null);
            vh = new ViewHolder();
            vh.building_edit_flag = (CheckBox) convertView
                    .findViewById(R.id.room_img_check);
    
            vh.building_image = (ImageView) convertView
                    .findViewById(R.id.item_room_new_building_image);
            vh.building_name = (TextView) convertView
                    .findViewById(R.id.item_room_new_building_name);
            vh.building_address = (TextView) convertView
                    .findViewById(R.id.item_room_new_building_address);
            vh.building_first_price = (TextView) convertView
                    .findViewById(R.id.item_room_new_building_first_price);
            vh.building_unit_price = (TextView) convertView
                    .findViewById(R.id.item_room_new_building_unit_price);
            vh.building_DISTANCE = (TextView) convertView
                    .findViewById(R.id.textView1);
            vh.title = (ImageView) convertView
                    .findViewById(R.id.room_img_title);
            vh.building_label_1 = (ImageView) convertView
                    .findViewById(R.id.item_room_new_building_label_1);
            vh.building_label_2 = (ImageView) convertView
                    .findViewById(R.id.item_room_new_building_label_2);
            vh.building_label_3 = (ImageView) convertView
                    .findViewById(R.id.item_room_new_building_label_3);
            checkBoxs.add(vh.building_edit_flag);
            convertView.setTag(vh);
        } else {
            convertView = inflater.inflate(
                    R.layout.browse_item_room_zufang_view, null);
            vh2 = new ViewHolder2();
            vh2.building_edit_flag = (CheckBox) convertView
                    .findViewById(R.id.room_img_check);
            checkBoxs.add(vh2.building_edit_flag);
            vh2.building_image = (ImageView) convertView
                    .findViewById(R.id.item_room_new_building_image);
            vh2.building_title = (TextView) convertView
                    .findViewById(R.id.item_room_zufang_title);
            vh2.building_address = (TextView) convertView
                    .findViewById(R.id.item_room_zufang_address);
            vh2.building_price = (TextView) convertView
                    .findViewById(R.id.item_room_zufang_junjia);
            vh2.building_zhengzu = (TextView) convertView
                    .findViewById(R.id.item_room_zhengzu);
            vh2.building_countf = (TextView) convertView
                    .findViewById(R.id.item_room_zufang_shi_ting);
            vh2.building_label_1 = (ImageView) convertView
                    .findViewById(R.id.item_room_new_building_label_1);
            vh2.building_label_2 = (ImageView) convertView
                    .findViewById(R.id.item_room_new_building_label_2);
            vh2.building_label_3 = (ImageView) convertView
                    .findViewById(R.id.item_room_new_building_label_3);
            convertView.setTag(vh2);
        }
    } else {
        if (getItemViewType(position) == 0) {
            vh = (ViewHolder) convertView.getTag();
            String flg1 = entity.getFLG1();
            String flg2 = entity.getFLG2();
            String flg3 = entity.getFLG3();
            if (!"".equals(flg1)) {
                vh.building_label_1.setVisibility(View.VISIBLE);
                setImg(vh.building_label_1, flg1);
            } else {
                vh.building_label_1.setVisibility(View.GONE);
            }
            if (!"".equals(flg2)) {
                vh.building_label_2.setVisibility(View.VISIBLE);
                setImg(vh.building_label_2, flg2);
            } else {
                vh.building_label_2.setVisibility(View.GONE);
            }
            if (!"".equals(flg3)) {
                vh.building_label_3.setVisibility(View.VISIBLE);
                setImg(vh.building_label_3, flg3);
            } else {
                vh.building_label_3.setVisibility(View.GONE);
            }
    
            if ("1".equals(entity.getHotMarks())) {
                vh.title.setVisibility(View.VISIBLE);
                vh.title.setImageResource(R.drawable.hot);
            } else {
                if ("1".equals(entity.getNewMarks())) {
                    vh.title.setVisibility(View.VISIBLE);
                    vh.title.setImageResource(R.drawable.latest);
                } else {
                    vh.title.setVisibility(View.GONE);
                }
            }
    
        } else {
            vh2 = (ViewHolder2) convertView.getTag();
            String flg1 = entity.getFLG1();
            String flg2 = entity.getFLG2();
            String flg3 = entity.getFLG3();
            if (!"".equals(flg1)) {
                vh2.building_label_1.setVisibility(View.VISIBLE);
                setImg(vh2.building_label_1, flg1);
            } else {
                vh2.building_label_1.setVisibility(View.GONE);
            }
            if (!"".equals(flg2)) {
                vh2.building_label_2.setVisibility(View.VISIBLE);
                setImg(vh2.building_label_2, flg2);
            } else {
                vh2.building_label_2.setVisibility(View.GONE);
            }
            if (!"".equals(flg3)) {
                vh2.building_label_3.setVisibility(View.VISIBLE);
                setImg(vh2.building_label_3, flg3);
            } else {
                vh2.building_label_3.setVisibility(View.GONE);
            }
        }
    }
    if (getItemViewType(position) == 0) {
        final String ImgUrl = entity.getImgUrl();
        if ("null".equals(ImgUrl) || ImgUrl == null || "".equals(ImgUrl)) {
            vh.building_image
                    .setBackgroundResource(R.drawable.list_home_image);
        } else {
            MainActivity.imageLoader_mid.DisplayImage(ImgUrl,
                    vh.building_image);
        }
        String EstateName = entity.getEstateName();
        String CountF = entity.getCountF();
        String Square = entity.getSquare();
        String PropertyDirection = entity.getPropertyDirection();
        String PropertyDecoration = entity.getPropertyDecoration();
        String PropertyType = entity.getPropertyType();
        final String ProAvgPrice = entity.getProAvgPrice();
        String Price = entity.getPrice();
        String CountH = entity.getCountH();
        final String DISTANCE = entity.getDISTANCE();
        double d = 0;
        DecimalFormat df = null;
        String a = "";
        if (DISTANCE != null) {
            if (!"0".equals(DISTANCE)) {
                d = Double.parseDouble(DISTANCE);
                df = new DecimalFormat(".00");
                a = df.format(d) + "km";
            } else {
                a = "--km";
            }
        }
        if (mType == EditType.NO_EDIT) {
            vh.building_edit_flag.setVisibility(View.GONE);
        } else {
            vh.building_edit_flag.setVisibility(View.VISIBLE);
            convertView.setOnClickListener(new ClickListener(position));
            // TODO caoyx3
            vh.building_edit_flag
                    .setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
                        @Override
                        public void onCheckedChanged(
                                CompoundButton buttonView, boolean isChecked) {
                            // TODO Auto-generated method stub
                            if (isChecked) {
                                arrayList.get(position).setFlag(true);
                            } else {
                                arrayList.get(position).setFlag(false);
                            }
    
                        }
                    });
            vh.building_edit_flag.setChecked(arrayList.get(position)
                    .isFlag());
            // if (mType == EditType.EDIT) {
            // }
        }
        vh.building_name.setText(EstateName + ", " + CountF + "室, "
                + Square + "平");
        vh.building_address.setText(PropertyDirection + " "
                + PropertyDecoration + " " + PropertyType + "/共" + CountH
                + "层");
        vh.building_first_price.setText(ProAvgPrice + "元/㎡");
        vh.building_unit_price.setText(Price + "万");
        vh.building_DISTANCE.setText(a);
    } else {
        final String ImgUrl = entity.getImgUrl();
        if ("null".equals(ImgUrl) || ImgUrl == null || "".equals(ImgUrl)) {
            vh2.building_image
                    .setBackgroundResource(R.drawable.list_home_image);
        } else {
            MainActivity.imageLoader_mid.DisplayImage(ImgUrl,
                    vh2.building_image);
        }
        final String PropertyId = entity.getPropertyId();
        final String EstateName = entity.getEstateName();
        String CountF = entity.getCountF();
        String CountT_Property = entity.getCountT_Property();
        String Square = entity.getSquare();
        String RentType = entity.getRentType();
        final String RentPrice = entity.getRentPrice();
        if (mType == EditType.NO_EDIT) {
            vh2.building_edit_flag.setVisibility(View.GONE);
        } else {
            vh2.building_edit_flag.setVisibility(View.VISIBLE);
            convertView.setOnClickListener(new ClickListener(position));
            // TODO caoyx3
            vh2.building_edit_flag
                    .setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
                        @Override
                        public void onCheckedChanged(
                                CompoundButton buttonView, boolean isChecked) {
                            // TODO Auto-generated method stub
                            if (isChecked) {
                                arrayList.get(position).setFlag(true);
                            } else {
                                arrayList.get(position).setFlag(false);
                            }
                        }
                    });
            vh2.building_edit_flag.setChecked(arrayList.get(position)
                    .isFlag());
    
            // if (mType == EditType.EDIT) {
            // }
        }
        vh2.building_title.setText(EstateName + ", " + Square + "平");
        vh2.building_address.setText(EstateName);
        vh2.building_price.setText(RentPrice + "元/月");
        vh2.building_zhengzu.setText(RentType);
        vh2.building_countf.setText(CountF + "室" + CountT_Property + "厅");
    }
    return convertView;
    

    }

    // class MyAdapterListener implements OnCheckedChangeListener {
    //
    // private int position;
    // private String name;
    // private String pid;
    // private CheckBox box;
    //
    // public MyAdapterListener(int pos, String name, String pid, CheckBox box)
    // {
    // position = pos;
    // this.name = name;
    // this.pid = pid;
    // this.box = box;
    // }
    //
    // @Override
    // public void onCheckedChanged(CompoundButton buttonView,
    // boolean isChecked) {
    //
    // CheckBox box = (CheckBox) buttonView;
    // data.position = position;
    // data.name = name;
    // data.pid = pid;
    //
    // if (isChecked) {
    // checkBoxs.add(box);
    // datas.add(data);
    // box.setBackgroundResource(R.drawable.icon_duigougraygdd);
    // } else {
    // box.setBackgroundResource(R.drawable.icon_duigouredgdd);
    // }
    // }
    //
    // }
    //
    // class MyOnClickListener implements View.OnClickListener {
    //
    // private int position;
    // private String name;
    // private String pid;
    // private CheckBox box;
    //
    // public MyOnClickListener(int pos, String name, String pid, CheckBox box)
    // {
    // position = pos;
    // this.name = name;
    // this.pid = pid;
    // this.box = box;
    // }
    //
    // @Override
    // public void onClick(View v) {
    //
    // data.position = position;
    // data.name = name;
    // data.pid = pid;
    //
    // if (box.isChecked()) {
    // checkBoxs.add(box);
    // datas.add(data);
    // box.setBackgroundResource(R.drawable.icon_duigougraygdd);
    // } else {
    // box.setBackgroundResource(R.drawable.icon_duigouredgdd);
    // }
    // }
    //
    // }

    public void notifyAllChecked() {
    for (int i = 0; i < checkBoxs.size(); i++) {
    checkBoxs.get(i).setChecked(true);
    }
    notifyDataSetChanged();
    }

    public void notifyAllNotCheck() {
    for (int i = 0; i < checkBoxs.size(); i++) {
    checkBoxs.get(i).setChecked(false);
    }
    notifyDataSetChanged();
    }

    private void setImg(ImageView img, String flg1) {
    if ("地铁房".equals(flg1)) {
    img.setImageResource(R.drawable.room_ditiefang);
    }
    if ("学区房".equals(flg1)) {
    img.setImageResource(R.drawable.room_xuequfang);
    }
    if ("钥匙房".equals(flg1)) {
    img.setImageResource(R.drawable.room_yaochifang);
    }
    if ("满二唯一".equals(flg1)) {
    img.setImageResource(R.drawable.room_manerweiyi);
    }
    if ("急售房".equals(flg1)) {
    img.setImageResource(R.drawable.room_jishoufang);
    }
    if ("经理推荐".equals(flg1)) {
    img.setImageResource(R.drawable.room_jinglituijian);
    }
    }

    @Override
    public int getViewTypeCount() {
    return 2;
    }

    @Override
    public int getItemViewType(int position) {
    if (getItem(position).getType() == Type.HANDE_HOUSE) {
    return 0;
    } else {
    return 1;
    }
    }

    @Override
    public void notifyDataSetChanged() {
    super.notifyDataSetChanged();
    }

    // public void notifyShowCheckBox() {
    // if (flag == true) {
    // notifyDataSetChanged();
    // count = 1;
    // flag = false;
    // } else if (flag == false) {
    // views.clear();
    // initDatas();
    // notifyDataSetChanged();
    // count = 0;
    // flag = true;
    // }
    // }
    //
    // public void notifyInitCheckBox() {
    // for (int i = 0; i < checkBoxs.size(); i++) {
    // checkBoxs.get(i).setChecked(false);
    // }
    // }
    //
    // private void initDatas() {
    // if (datas.size() != 0) {
    // datas.clear();
    // }
    // }

    public class Data {
    int position;
    String pid;
    String name;

    public int getPosition() {
        return position;
    }
    
    public String getPid() {
        return pid;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    

    }

    public List getViews() {
    return views;
    }

    public List getDatas() {
    return datas;
    }

    private void notifyActivity(int position, CheckBox cb) {
    ReMenEntityBrowse reMenEntity = RecentVisitActivity.arrayList
    .get(position);
    if (cb.isChecked()) {
    reMenEntity.setFlag(true);
    } else {
    reMenEntity.setFlag(false);
    }
    }

    class ViewHolder {
    ImageView building_image;
    TextView building_name;
    TextView building_address;
    TextView building_unit_price;
    TextView building_first_price;
    TextView building_DISTANCE;
    ImageView building_label_1;
    ImageView building_label_2;
    ImageView building_label_3;
    ImageView title;
    CheckBox cb;
    CheckBox building_edit_flag;
    }

    class ViewHolder2 {
    ImageView building_image;
    TextView building_title;
    TextView building_zhengzu;
    TextView building_countf;
    TextView building_price;
    TextView building_address;
    ImageView building_label_1;
    ImageView building_label_2;
    ImageView building_label_3;
    ImageView title;
    CheckBox cb;
    CheckBox building_edit_flag;
    }

}

bdmh
bdmh   Ds   Rxr 2016.04.01 11:35

贴代码都贴不合适,你要贴getview处的代码,先跟踪list中的数据是否正常

qq_30562993
qq_30562993   2016.04.01 12:17

图片说明,我在断点里面看了,每次给list中add的数据是正常的,就是只显示最后一条数据

qq_30562993
qq_30562993   2016.04.01 12:17

图片说明,我在断点里面看了,每次给list中add的数据是正常的,就是只显示最后一条数据

dongfeng9ge
dongfeng9ge   Ds   Rxr 2016.04.01 12:55

别发图,复制粘贴代码贴上来

qq_30562993
qq_30562993   2016.04.01 13:27

try {
JSONObject jo = new JSONObject(read);
JSONArray jsonArrayList = (JSONArray) jo.get("bicyclelist");
List list = new ArrayList();
int j;
for (j = 0; j < jsonArrayList.length(); j++) {

            JSONObject o = (JSONObject) jsonArrayList.get(j);
            YABicycle yaz = new YABicycle();
            yaz.setModel(o.getString("model"));
            yaz.setPoliceNum(o.getString("policeNum"));
            yaz.setMotorNumber(o.getString("motorNumber"));
            yaz.setRfid(o.getString("rfid"));
            yaz.setVehicleIdentifyNumber(o.getString("vehicleIdentifyNumber"));
            yaz.setShoppingTime(o.getString("shoppingTime"));
            yaz.setPrice(o.getString("price"));
            yaz.setBicycleOwnerID(o.getString("bicycleOwnerID"));
            yaz.setId(o.getString("id"));

            yaz.setLicenseUrl(o.getString("licenseUrl"));
            yaz.setBrandUrl(o.getString("brandUrl"));
            yaz.setFrontUrl(o.getString("frontUrl"));
            yaz.setBackUrl(o.getString("backUrl"));
            yaz.setIdentityCardForwardUrl(o.getString("identityCardForwardUrl"));
            yaz.setIdentityCardBackUrl(o.getString("identityCardBackUrl"));
            String m = yaz.getModel();
            list.add(j, yaz);

        }
        CustomAdapter adapter = new CustomAdapter(this, list, R.layout.layout_rg_review_items);
        listview.setAdapter(adapter);
        mProgressDialog.dismiss();
    } catch (Exception e) {
        // TODO: handle exception
        mProgressDialog.dismiss();
        To.showShort(BicycleCount.this, "数据解析错误!");
    }


    getview:


        if (resource == R.layout.layout_rg_review_items) {

        YABicycle yab = (YABicycle) list.get(position);

        Bitmap bitmap = BitmapFactory.decodeFile(yab.getLicenseUrl(), getBitmapOption(2));
        cache.review_item_photo_iv.setImageBitmap(bitmap);
        cache.model.setText(yab.getModel());
        cache.policeNum.setText(yab.getPoliceNum());
        cache.vehicleIdentifyNumber.setText(yab.getVehicleIdentifyNumber());
        cache.motorNumber.setText(yab.getMotorNumber());
        cache.rfid.setText(yab.getRfid());
        cache.review_item_image.setText("已安裝");
        cache.review_item_image.setTextColor(Color.parseColor("#ff0000"));

    }
cyxevil
cyxevil   2016.04.01 13:51

你把适配器整个发过来,你这个解析的代码能看出什么,展示的代码都没有

cyxevil
cyxevil 回复cyxevil: package com.bypro.adapter.visit;
一年多之前 回复
cyxevil
cyxevil 回复qq_30562993: 这里有个用多个布局的,给你参考一下
一年多之前 回复
cyxevil
cyxevil 回复qq_30562993: 你的控件不是应该直接用缓存对象吗
一年多之前 回复
cyxevil
cyxevil 回复qq_30562993: 我具体也没看出哪里的问题,但是你的 cache = new ViewHolder();对象的顺序有问题
一年多之前 回复
qq_30562993
qq_30562993 下面就是适配器了。
一年多之前 回复
qq_30562993
qq_30562993   2016.04.01 13:56

package com.example.handheldterminal.adapter;

import java.util.List;

import com.example.handheldterminal.R;
import com.example.handheldterminal.util.Bicycle;
import com.example.handheldterminal.util.RadarEntity;
import com.example.handheldterminal.util.StolenTrack;
import com.example.handheldterminal.util.YABicycle;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**

  • 自定义适配器
  • @author
    */
    public class CustomAdapter extends BaseAdapter {

    @SuppressWarnings("unused")
    private static final String TAG = "CustomAdapter";
    private List<?> list; // 需要绑定的数据
    private LayoutInflater inflater; // 布局填充器,使用ListView的条目item.xml生成对应的view
    private int resource; // 要绑定的条目界面
    @SuppressWarnings("unused")
    private Context context;

    @SuppressWarnings("static-access")
    public CustomAdapter(Context context, List<?> list, int resource) {
    this.list = list;
    this.resource = resource;
    this.context = context;
    // 获取系统内部的布局填充服务
    inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    }

    /**

    • 获取ListView条目的总数量
    • @return 返回总数量 */ @Override public int getCount() { return list == null ? 0 : list.size(); }

    /**

    • 获取当前ListView条目的位置 */ @Override public Object getItem(int position) { return list == null ? 0 : list.get(position); }

    /**

    • 获取当前ListView条目id */ @Override public long getItemId(int position) { return position; }

    /**

    • 获取当前ListView条目view对象
      */
      @SuppressLint("SimpleDateFormat")
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
      TextView content = null;
      TextView mailTitle = null;
      TextView dateTime = null;
      TextView userName = null;
      TextView model = null;
      TextView policeNum = null;
      TextView vehicleIdentifyNumber = null;
      TextView motorNumber = null;
      TextView rfid = null;
      TextView review_item_image = null;

      TextView review_item_PRmodle = null;
      TextView review_item_PRname = null;
      TextView review_item_PRmotorNum = null;
      TextView review_item_PRphone = null;
      TextView review_PR = null;

      ImageView review_item_photo_iv = null;
      ViewHolder cache = null;
      ImageView ivImage = null;
      TextView stolent = null;
      // 判断convertView是否为null,如果是则进行第一次数据的加载,否则就进行数据的缓存,从而重用。
      if (convertView == null) {
      convertView = inflater.inflate(resource, null);
      if (resource == R.layout.bdxc_listview_item) {
      ivImage = (ImageView) convertView.findViewById(R.id.bdxciv_vehicles);
      dateTime = (TextView) convertView.findViewById(R.id.bdxctv_name_value);
      content = (TextView) convertView.findViewById(R.id.bdxctv_phone_value);
      userName = (TextView) convertView.findViewById(R.id.bdxctv_pinp_value);
      mailTitle = (TextView) convertView.findViewById(R.id.bdxctv_color_value);
      }
      if (resource == R.layout.stolen_track_item) {
      stolent = (TextView) convertView.findViewById(R.id.stolenitem_textview);
      }
      if (resource == R.layout.layout_rg_review_items) {
      model = (TextView) convertView.findViewById(R.id.review_item_modle_tv);
      policeNum = (TextView) convertView.findViewById(R.id.review_item_name_tv);
      vehicleIdentifyNumber = (TextView) convertView.findViewById(R.id.review_item_phone_tv);
      motorNumber = (TextView) convertView.findViewById(R.id.review_item_motorNum_tv);
      rfid = (TextView) convertView.findViewById(R.id.review_item_rfid1_tv);
      review_item_image = (TextView) convertView.findViewById(R.id.review_item_image);
      review_item_photo_iv = (ImageView) convertView.findViewById(R.id.review_item_photo_iv);
      }
      if (resource == R.layout.lyaout_pr_listitem) {
      review_item_PRmodle = (TextView) convertView.findViewById(R.id.review_item_PRmodle);
      review_item_PRname = (TextView) convertView.findViewById(R.id.review_item_PRname);
      review_item_PRmotorNum = (TextView) convertView.findViewById(R.id.review_item_PRmotorNum);
      review_item_PRphone = (TextView) convertView.findViewById(R.id.review_item_PRphone);
      review_PR = (TextView) convertView.findViewById(R.id.review_PR);
      }
      cache = new ViewHolder();
      cache.model = model;
      cache.policeNum = policeNum;
      cache.vehicleIdentifyNumber = vehicleIdentifyNumber;
      cache.motorNumber = motorNumber;
      cache.rfid = rfid;
      cache.review_item_image = review_item_image;
      cache.review_item_photo_iv = review_item_photo_iv;
      cache.review_item_PRmodle = review_item_PRmodle;
      cache.review_item_PRname = review_item_PRname;
      cache.review_item_PRmotorNum = review_item_PRmotorNum;
      cache.review_item_PRphone = review_item_PRphone;
      cache.review_PR = review_PR;
      cache.content = content;
      cache.title = mailTitle;
      cache.dateTime = dateTime;
      cache.userName = userName;
      cache.ivImage = ivImage;
      cache.stolent = stolent;

      convertView.setTag(cache); // 临时存放缓存的对象
      

      } else {
      cache = (ViewHolder) convertView.getTag(); // 获取第一页缓存的条目
      content = cache.content;
      mailTitle = cache.title;
      dateTime = cache.dateTime;
      userName = cache.userName;
      ivImage = cache.ivImage;
      stolent = cache.stolent;

      model = cache.model;
      policeNum = cache.policeNum;
      vehicleIdentifyNumber = cache.vehicleIdentifyNumber;
      motorNumber = cache.motorNumber;
      rfid = cache.rfid;
      

      }
      // 以下为数据的绑定
      if (resource == R.layout.bdxc_listview_item) {
      RadarEntity entity = (RadarEntity) list.get(position);
      cache.ivImage.setImageResource(entity.getIvImage());
      cache.content.setText(entity.getContent());
      cache.title.setText(entity.getMailTitle());
      cache.dateTime.setText(entity.getDateTime());
      cache.userName.setText(entity.getUserName());
      }
      if (resource == R.layout.stolen_track_item) {
      StolenTrack entity = (StolenTrack) list.get(position);
      cache.stolent.setText(entity.getContent());
      }
      if (resource == R.layout.layout_rg_review_items) {

      YABicycle yab = (YABicycle) list.get(position);
      
      Bitmap bitmap = BitmapFactory.decodeFile(yab.getLicenseUrl(), getBitmapOption(2));
      cache.review_item_photo_iv.setImageBitmap(bitmap);
      cache.model.setText(yab.getModel());
      cache.policeNum.setText(yab.getPoliceNum());
      cache.vehicleIdentifyNumber.setText(yab.getVehicleIdentifyNumber());
      cache.motorNumber.setText(yab.getMotorNumber());
      cache.rfid.setText(yab.getRfid());
      cache.review_item_image.setText("已安裝");
      cache.review_item_image.setTextColor(Color.parseColor("#ff0000"));
      

      }
      if (resource == R.layout.lyaout_pr_listitem) {
      Bicycle bicycle = (Bicycle) list.get(position);
      cache.review_item_PRmodle.setText(bicycle.getModel());
      cache.review_item_PRname.setText(bicycle.getBicycleOwnerName());
      cache.review_item_PRmotorNum.setText(bicycle.getVehicleIdentifyNumber());
      cache.review_item_PRphone.setText(bicycle.getMotorNumber());
      cache.review_PR.setText("已预安裝");
      cache.review_PR.setTextColor(Color.parseColor("#33cc33"));
      }
      return convertView;
      }

    private Options getBitmapOption(int inSampleSize) {
    System.gc();
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPurgeable = true;
    options.inSampleSize = inSampleSize;
    return options;
    }

    private class ViewHolder {
    public TextView content;
    public TextView title;
    public TextView dateTime;
    public TextView stolent;
    public TextView userName;
    public ImageView ivImage;
    public TextView model = null;
    public TextView policeNum = null;
    public TextView vehicleIdentifyNumber = null;
    public TextView motorNumber = null;
    public TextView rfid = null;
    public TextView review_item_image = null;
    public ImageView review_item_photo_iv = null;
    public TextView review_item_PRmodle = null;
    public TextView review_item_PRname = null;
    public TextView review_item_PRmotorNum = null;
    public TextView review_item_PRphone = null;
    public TextView review_PR = null;
    }
    }

sl_18500
sl_18500   2016.04.01 15:27

你只显示一个数据,那你就传一个数据啊

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!