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

问题描述

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

解决方案

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;
    }

}

解决方案二:

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

解决方案三:

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

解决方案四:

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

解决方案五:

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

解决方案六:

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"));

    }

解决方案七:

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

解决方案八:

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;
    }
    }

解决方案九:

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

时间: 2024-10-28 20:55:32

listview 只显示最后一条数据,帮忙看看吧的相关文章

各路好汉大神,急需救助,我写的数据库代码在显示数据时,只显示最后一条

问题描述 各路好汉大神,急需救助,我写的数据库代码在显示数据时,只显示最后一条 我写的代码如下: Sub depart(ByVal a As String) Dim i As Short Dim j As Short Dim n As Integer Dim k As Integer n = DataSet11.Tables(""timing"").Rows.Count ' If InStr(1 a*"") = 0 Then ' 以防没有数字直接

用时间控制要变化的数据怎么做呢-- 一条数据显示一天。到第二天显示下一条数据

问题描述 我有个表例如:idtitle1中国你好,我爱中国2你来了.我叫的么3怎么区别你和我的存在我在页面中用一个table显示其中的一条数据但是我的条件是一条数据显示一天.到第二天显示下一条数据我应该怎么写这个sql语句呢 解决方案 解决方案二:获取下一次显示的数据再定时执行解决方案三:或者直接写在代码里面判断当时间为24:00:00是获取下一条再显示

hibernate 循环遍历 list对象,只保存最后一条数据,偶现

问题描述 hibernate 循环遍历 list对象,只保存最后一条数据,偶现 @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public String rankScoreIn(MultipartFile file, String classid, String testname, String grad, String subject) { StringBuilder failureMsg = new

npoi导出的时候只导出最后一条数据

问题描述 npoi导出的时候只导出最后一条数据 public void Export(HttpContext context) { context.Response.ContentType = "application/vnd.ms-excel;charset=UTF-8"; //文件名进行url编码,防止乱码 string strFileName = HttpUtility.UrlDecode("班级平均分排名.xls"); context.Response.Ad

Android编程实现Toast只显示最后一条的方法

本文实例讲述了Android编程实现Toast只显示最后一条的方法.分享给大家供大家参考,具体如下: 在做Android开发中,时不时的可能会用到Toast,但用Toast的时候,连续使用会存在一个问题,就是一条条显示Toast.而不是直接显示最后一条.因此,根据此需求,现在写了ToastUtil这个类,该类中有三个方法供选择. ToastUtil.Java import android.content.Context; import android.graphics.PixelFormat;

【问题解决】Mybatis一对多/多对多查询时只查出了一条数据

问题描述: 如果三表(包括了关系表)级联查询,主表和明细表的主键都是id的话,明细表的多条数据只能查询出来第一条/最后一条数据. 三个表,权限表(Permission),权限组表(PermissionGroup),权限组与权限的关系表(PermissionPermissionGroupKey) 实体类就不写上来了. 原出错映射文件: <resultMap id="permissionGroupResultMap" type="cn.kx59.admin.entity.P

MVC3 视图两表联查 返回的结果集只循环了第一条数据

问题描述 实体类namespaceMusicStore.Models{publicclassDBView{[Key]publicintGenreId{get;set;}publicstringName{get;set;}publicstringTitle{get;set;}publicstringPrice{get;set;}}}接口实现namespaceMusicStore.Models{publicclassMusicStoreEntities:DbContext{publicDbSet<D

repeater和数据库相连,在repeater中显示了很多条数据,我通过什么方法可以操作其中一条数据呢?

问题描述 我用repeater控件和数据库相连,显示数据.作者:<%#DataBinder.Eval(Container.DataItem,"username")%><%#ShowDeleteLink(DataBinder.Eval(Container.DataItem,"itemid").ToString())%>其中ShowDeleteLink()如下protectedstringShowDeleteLink(stringitemid){

让GridView只显示特定用户的数据的方法_实用技巧

1.新建一个Label1来储存username,这个是我这个方法成功的关键,因为我尝试用Session("username")失败. 改用control 来传递变量,成功! 2."GridView tasks"--"configure Data Source"--一路next下去---到了"Define Custom Statements or Stored Procedures"窗口.把SQL Selete 语句 SELEC