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;
2 年多之前 回复
cyxevil
cyxevil 回复qq_30562993: 这里有个用多个布局的,给你参考一下
2 年多之前 回复
cyxevil
cyxevil 回复qq_30562993: 你的控件不是应该直接用缓存对象吗
2 年多之前 回复
cyxevil
cyxevil 回复qq_30562993: 我具体也没看出哪里的问题,但是你的 cache = new ViewHolder();对象的顺序有问题
2 年多之前 回复
qq_30562993
qq_30562993 下面就是适配器了。
2 年多之前 回复
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币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
ScrollView中的ListView只显示一条数据的解决方法
在ScrollView中嵌套ListView,会出现ListView只显示一条数据的现象,解决方法有两种,如下: 1. 在Activity中list view.setAdapter以后执行如下方法 public class MainActivity extends Activity { private ListView listView; @Override
Android 自定义ListView只显示第一条数据的问题
最近,要在应用中做一个功能,查询SQLite数据库中的记录,用列表进行展示。 关于选择哪种布局,因为考虑到界面上要增加一些筛选条件,界面会稍显复杂,所以就没有继承ListFragment,而是继承了Fragment,并且用了自定义的ListView: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android
Dialog嵌套listview最后一行被遮盖问题
最近项目中实现了一个功能 Dialog中嵌套ListView 顺利完成后 发现最后一行数据有被遮盖的问题  先上代码 Drawable drawable = getResources().getDrawable(R.drawable.transparent);; LayoutInflater inflater = LayoutInflater.from(this
Android 自定义Adapter 但listview 只显示第一条数据
楼主让这个问题郁闷了一晚上。。。。。在logcat里明明显示adapter的getview方法里的list大于一条数据 ,但posotion却一直是0.。。。。运行后也只显示list[0]里面的数据。。。。最后的最后原来错误出在布局文件上    我以前的是这样的; <ScrollView android:layout_width="fill_parent"
android- ScrollView与ListView冲突(最后一条Item显示不全)
在ScrollView中嵌套ListView(或者ScrollView)的另外一个问题就是,子ScrollView中无法滑动的(如果它没有显示完全的话),因为滑动事件会被父ScrollView吃掉,如果想要让子ScrollView也可以滑动,只能强行截取滑动事件。 子ListView的每个Item必须是LinearLayout,不能是其他的,因为其他的Layout(如RelativeLayout
有时候开发listView需要默认显示到最后一条数据
想要实现一个listview初始化时和数据变化后显示到列表的最末,简单地说就是像聊天窗或者是日志输出那样的情景。 开始没去仔细看listview对象的属性,按照惯性思维就去 调用 listView.scrollTo(offset_x,offset_y); 然后又被一篇奇怪的日志误导了什么外层容器和 内层两个view ...干!浪费我时间。 其实listView
android listview 只显示一行
今天碰到一个很诡异的问题:listview里面的adapter有4行数据,可是在页面上无论如何只能显示list.get(0)的数据,其他三项无法显示。 原来,android在layout布局文件的开头里面,有一行这个东西     android:layout_width="fill_parent"     android:layout_height="fill_parent" >
设置listView总是显示最后一条
listView.setselection(listView.getBottom) 或者 listView.setselection(adapter.getCount())
ListView显示最后一条Item不完整问题分析
比如,有这么一个需求:实现一个IM类型的app聊天界面 要如何做呢? 很简单,一个title在顶部,一个输入框+按钮在底部 ,中间是一个ListView,搞定!!! 然后,ListView需要动态添加Item内容,并且,每添加一条Item都需要将ListView显示在最后一条。 好了,这次要解决的就是上面加粗部分的问题。 这时候有人要说了,调用setSelection()
android ListView中只显示一个item问题的两种解决办法
为什么会listview中显示一个item,而本身数据有多个item?  存在原因有两点: 1.该listview存在于listview的嵌套下 2.该listview存在于scrollview下或者具有scrollview滑动功能的控件下   解决办法:1根据item的高度和list的size来计算高度,然后重新在代码中对listview进行高度的设置 这种方式网上有很