关于listview上下滑动imageview图片混乱问题

问题代码:
@Override
public View getView(int position, View view, ViewGroup parent)
{
    final ViewHolder mViewHolder;
    if(null == view){
        mViewHolder = new ViewHolder();
        view = LayoutInflater.from(mContext).inflate(R.layout.fragment_deal_order_list_item, null);

        mViewHolder.txtOrderDealstatus = (ImageView) view.findViewById(R.id.order_deal_status);
        mViewHolder.txtOrderNumber = (TextView) view.findViewById(R.id.dealorder_number);
         mViewHolder.txtOrderNum = (TextView) view.findViewById(R.id.deal_order_num);
        mViewHolder.txtDealOrderTime = (TextView) view.findViewById(R.id.dealorder_time);
        mViewHolder.txtCustomerName = (TextView) view.findViewById(R.id.customer_name);
        mViewHolder.txtCustomerAddress = (TextView) view.findViewById(R.id.customer_address);
        mViewHolder.txtOrderSendTime = (TextView) view.findViewById(R.id.customer_post_time);
        mViewHolder.txtOrderGoodsDes = (TextView) view.findViewById(R.id.customer_list_goods_des);

        mViewHolder.txtCustomerPhone = (TextView) view.findViewById(R.id.customer_phone);

        mViewHolder.txtPostManName = (TextView) view.findViewById(R.id.postman_name);
        mViewHolder.txtPostManPhone = (TextView) view.findViewById(R.id.postman_phone);
        mViewHolder.listgoods = (ListView) view.findViewById(R.id.customer_list_goods);
        mViewHolder.linerDealOrderTitle = (LinearLayout) view.findViewById(R.id.deal_order_item_title);
        mViewHolder.linearDeralOrderCotent = (LinearLayout) view.findViewById(R.id.show_order_message);
        mViewHolder.linearPosterCotentTitle = (LinearLayout) view.findViewById(R.id.poster_message_title);
        mViewHolder.linearPosterCotent = (LinearLayout) view.findViewById(R.id.poster_message);
        view.setTag(mViewHolder);
    }
    else
    {
        mViewHolder = (ViewHolder) view.getTag();
    }

    if(listOrder.get(position).getPostmanid() == null || listOrder.get(position).getPostmanid() == 0)
    {
        mViewHolder.linearPosterCotentTitle.setVisibility(View.GONE);
        mViewHolder.linearPosterCotent.setVisibility(View.GONE);
    }
    Log.i("DealOrderAdapter","position:" + position);
    if(listOrder.get(position).getOrderSeller().getSellerordersequence() == null)
    {
        mViewHolder.txtOrderNum.setText("#");
    }
    else
    {
        int sequence = listOrder.get(position).getOrderSeller().getSellerordersequence();
        mViewHolder.txtOrderNum.setText("#" + String.format("%02d",sequence));
    }

    mViewHolder.txtOrderNumber.setText(String.valueOf(listOrder.get(position).getOrderSeller().getSellerordernum()));
    mViewHolder.txtDealOrderTime.setText(listOrder.get(position).getOrdertime());
    mViewHolder.txtPostManName.setText(listOrder.get(position).getPostmanname());
    mViewHolder.txtPostManPhone.setText(listOrder.get(position).getPostmanphonenum());

    mViewHolder.txtCustomerName.setText(listOrder.get(position).getAcceptname());
    mViewHolder.txtCustomerAddress.setText(listOrder.get(position).getAcceptlocation());
    mViewHolder.txtOrderSendTime.setText(listOrder.get(position).getGoodsarrivetime());
    mViewHolder.txtOrderGoodsDes.setText(listOrder.get(position).getOrderSeller().getRemark());
    mViewHolder.txtCustomerPhone.setText(listOrder.get(position).getAcceptphonenum());

    Log.i("lxl","getSellerorderstatus:" + listOrder.get(position).getOrderSeller().getSellerorderstatus()
    + ";position:" + position);
    if(listOrder.get(position).getOrderSeller().getSellerorderstatus() == 2) {
        mViewHolder.txtOrderDealstatus.setImageResource(R.drawable.jujue);
    }
 

    OrderGoodsListItemAdapter mOrderGoodsListItemAdapter = new OrderGoodsListItemAdapter(mContext,
            listOrder.get(position).getOrderSeller().getLstOrderGoods());
    mViewHolder.listgoods.setAdapter(mOrderGoodsListItemAdapter);
    setListViewHeightOnChildren( mViewHolder.listgoods);


    return view;
}

public class ViewHolder{

    ImageView txtOrderDealstatus;
    TextView txtOrderNum;
    TextView txtOrderNumber;

    TextView txtDealOrderTime;
    TextView txtCustomerName;
    TextView txtCustomerPhone;
    TextView txtCustomerAddress;
    //送单时间
    TextView txtOrderSendTime;
    TextView txtOrderGoodsDes;
    TextView txtPostManName, txtPostManPhone;
    ListView listgoods;
    LinearLayout linerDealOrderTitle;
    LinearLayout linearDeralOrderCotent;
    LinearLayout linearPosterCotentTitle;
    LinearLayout linearPosterCotent;
}
上下滑动的时候,图片都变成了 R.drawable.jujue  默认图片是 R.drawable.queren
                              
修改:只是将if 后面加上else分之  这个bug就避免了
 
  
if(listOrder.get(position).getOrderSeller().getSellerorderstatus() == 2) {
    mViewHolder.txtOrderDealstatus.setImageResource(R.drawable.jujue);
}
else
{
    mViewHolder.txtOrderDealstatus.setImageResource(R.drawable.queren);
}
这个问题确实很奇怪!!! 只能说在listview的适配器 getview中 多处使用if分支,会对数据加载有影响,最好保证if else逻辑的完整性。
 
 

你可能感兴趣的:(Android开发)