LuckyJayce/MVCHelper

viewpager嵌套fragment,第一次加载有一条数据,刷新,服务器返回空数据,崩溃

wfs3006 opened this issue · 8 comments

qq 20170527103332
核心代码:
qq 20170527103522
手动刷新走到下面第四行,之后就崩溃了
qq 20170527103624

你的adaper 的代码贴出来看下,感觉adapter写的有问题

public class UserOrderAdapter extends BaseAdapter implements IDataAdapter<List>{

private List<PublisherOrder> itemList = new ArrayList<>();
private LayoutInflater inflater;
private Context context;
private int index;////根据顶部tab选择 显示待付款 待接单字样
private RefreshClickListener listener;

public UserOrderAdapter(Context context,int position){
    this.context = context;
    inflater = LayoutInflater.from(context);
    this.index = position;
}

public UserOrderAdapter(Context context, List<PublisherOrder> itemList, int position) {
    this.context = context;
    this.itemList = itemList;
    inflater = LayoutInflater.from(context);
    this.index = position;
}

public void setRefreshItemClickListener(RefreshClickListener listener) {
    this.listener = listener;
}

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

@Override
public Object getItem(int position) {
    return itemList.get(position);
}

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

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    RefreshViewHolder holder = null;

    if (convertView == null) {
            convertView = inflater.inflate(R.layout.layout_my_pub_order_item, null);
            holder = new RefreshViewHolder();
            holder.phone = (TextView) convertView.findViewById(R.id.my_pub_order_item_pub_phone);
            holder.userOwnStyle = (TextView) convertView.findViewById(R.id.my_pub_order_user_own_style);
            holder.goodImg = (ImageView) convertView.findViewById(R.id.my_pub_order_item_good_img);
            holder.title = (TextView) convertView.findViewById(R.id.my_pub_order_item_title);
            holder.content = (TextView) convertView.findViewById(R.id.my_pub_order_item_content);
            holder.money = (TextView) convertView.findViewById(R.id.my_pub_order_item_money);
            holder.btnLayout = convertView.findViewById(R.id.my_pub_order_btns_layout);
            holder.rootLayout = convertView.findViewById(R.id.my_pub_order_root_layout);
            holder.checkBtn = (TextView) convertView.findViewById(R.id.my_pub_order_check_btn);
            holder.cancelBtn = (TextView) convertView.findViewById(R.id.my_pub_order_cancel_btn);
            holder.img = (ImageView) convertView.findViewById(R.id.my_pub_order_item_img);
            holder.layoutTuEr = (LinearLayout) convertView.findViewById(R.id.layout_tuer);

        convertView.setTag(holder);
    } else {
        holder = (RefreshViewHolder) convertView.getTag();
    }

    final PublisherOrder pj = itemList.get(position);
    PublisherOrder.UinfoBean uinfoBean= pj.getUinfo();
    if(MyConstant.objectNotNull(uinfoBean)&&!TextUtils.isEmpty(uinfoBean.getIcon())){
        ImageOptions imageOptions = new ImageOptions.Builder()
                .setImageScaleType(ImageView.ScaleType.CENTER_CROP)
                .setCircular(true)
                .setCrop(false)
                .setLoadingDrawableId(R.mipmap.monkey)
                .setFailureDrawableId(R.mipmap.monkey)
                .setUseMemCache(true)
                .build();

        x.image().bind(holder.img,MyApplication.getFullImageURL(uinfoBean.getIcon()),imageOptions);
    }

    PublisherOrder.JobBean item = pj.getJob();

        holder.phone.setText(changePhoneNumStar(item.getSenderPhone()));//电话

        List<String> paths = JsonUtil.getListFromString(item.getImgPaths(),String.class);//图片
        if (MyConstant.listNotNull(paths)) {
            x.image().bind(holder.goodImg, MyApplication.getFullImageURL(paths.get(0)));
        } else {
            holder.goodImg.setVisibility(View.GONE);
        }

        if (!TextUtils.isEmpty(item.getTitle())) {//title
            holder.title.setText(item.getTitle());
        } else if (!TextUtils.isEmpty(item.getJobStyle())) {
            holder.title.setText(item.getJobStyle());
        }

        holder.content.setText(TextUtils.isEmpty(item.getExtraInfo()) ? "" : item.getExtraInfo());//内容
        holder.money.setText("¥ " + new DecimalFormat("0.00").format(Double.valueOf(item.getMoney()) / 100));

        switch (index) {//根据 userOwnStyle 类型进行显示 已完成是评论 未付款是付款 进行中是完成
            case 0:
                holder.checkBtn.setText("付款");
                holder.userOwnStyle.setText("等待付款");
                holder.cancelBtn.setVisibility(View.VISIBLE);
                holder.btnLayout.setVisibility(View.VISIBLE);
                break;
            case 1:
                List<PublisherOrder.SnatcherSimpleInfosBean> snatcherSimpleInfos = pj.getSnatcherSimpleInfos();
                if(MyConstant.listNotNull(snatcherSimpleInfos)){
                    holder.layoutTuEr.setVisibility(View.VISIBLE);
                    ImageView iv1 = (ImageView) convertView.findViewById(R.id.iv_tuer_1);
                    ImageView iv2 = (ImageView) convertView.findViewById(R.id.iv_tuer_2);
                    ImageView iv3 = (ImageView) convertView.findViewById(R.id.iv_tuer_3);
                    ImageView[] imageViews = {iv1,iv2,iv3};
                    int size = snatcherSimpleInfos.size();
                    for( int i=0;i<size;i++){
                        PublisherOrder.SnatcherSimpleInfosBean snatcherSimpleInfosBean = snatcherSimpleInfos.get(i);
                        if(i<3){
                            ImageOptions imageOptions = new ImageOptions.Builder()
                                    .setImageScaleType(ImageView.ScaleType.CENTER_CROP)
                                    .setCircular(true)
                                    .setCrop(false)
                                    .setLoadingDrawableId(R.mipmap.ic_default_header)
                                    .setFailureDrawableId(R.mipmap.ic_default_header)
                                    .setUseMemCache(true)
                                    .build();
                            x.image().bind(imageViews[i],MyApplication.getFullImageURL(snatcherSimpleInfosBean.getIcon()),imageOptions);
                        }
                    }
                    holder.layoutTuEr.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(context,SelectServerTodoActivity.class);
                            intent.putExtra("order",pj);
                            context.startActivity(intent);
                        }
                    });
                }else {
                    holder.layoutTuEr.setVisibility(View.GONE);
                }
                holder.userOwnStyle.setText("等待接单");
                holder.checkBtn.setText("");
                holder.checkBtn.setVisibility(View.GONE);
                holder.cancelBtn.setVisibility(View.VISIBLE);
                holder.btnLayout.setVisibility(View.VISIBLE);
                break;
            case 2:
                holder.checkBtn.setText("完成订单");
                holder.userOwnStyle.setText("正在进行");
                holder.cancelBtn.setVisibility(View.GONE);
                holder.btnLayout.setVisibility(View.VISIBLE);
                break;
            case 3:
                holder.userOwnStyle.setText("订单完成");
                holder.checkBtn.setText("评论");
                holder.cancelBtn.setVisibility(View.GONE);
                holder.btnLayout.setVisibility(View.VISIBLE);
                break;
            case 4:
                holder.userOwnStyle.setText("已退款");
                holder.checkBtn.setText("");
                holder.cancelBtn.setVisibility(View.GONE);
                holder.btnLayout.setVisibility(View.GONE);
                break;
        }

        holder.rootLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null)
                    listener.clickRootLayout(pj);
            }
        });

        holder.checkBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null)
                    listener.checkBtn(pj,index);
            }
        });

        //取消订单只有未付款才显示
        holder.cancelBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null)
                    listener.cancelBtn(pj,index);
            }
        });




    return convertView;
}

@Override
public void notifyDataChanged(List<PublisherOrder> publisherOrders, boolean isRefresh) {
    if (isRefresh) {
        itemList.clear();
    }
    itemList.addAll(publisherOrders);
    notifyDataSetChanged();
}

@Override
public List<PublisherOrder> getData() {
    return itemList;
}

public interface RefreshClickListener {
    void clickRootLayout(PublisherOrder job);//点击根布局(查看我服务的订单)

    void cancelBtn(PublisherOrder job, int position);//点击撤销按钮(查看我发布的订单)

    void checkBtn(PublisherOrder job, int index);//点击操作按钮(查看我发布的订单) 根据未付款、进行中、已完成有不同的点击操作
}


private class RefreshViewHolder {
    TextView content;//内容
    TextView userOwnStyle;//个人发布任务状态
    TextView money;//金额
    TextView title;//标题
    TextView phone;//发布者手机号
    ImageView img;//头像
    ImageView goodImg;//物品图片
    ImageView sideImg;//侧边图片
    View btnLayout;//底部按钮layout
    View rootLayout;//根layout
    TextView checkBtn;//操作按钮
    TextView cancelBtn;//撤销按钮
    LinearLayout layoutTuEr;//服务人员选择

}

//手机号 星号
private String changePhoneNumStar(String phone) {

    if (phone.length() == 11) {//如果是11位手机号
        phone = phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
    }

    return phone;
}

}

@LuckyJayce 发现问题了吗??

你有ListView有添加Header吧,那个代码也贴出来

@LuckyJayce 没有添加Header,这是布局文件
qq 20170628162239
这是代码
qq 20170628162419

@LuckyJayce 有时候不崩溃但是数据不刷新,麻烦有时间看一下
qq 20170629101102

问题描述,我也是使用的swiperefreshlayout,刚开始刷新,界面有一条数据,后台将数据清除完毕后,再次刷新,就会有楼上图中的样子,数据没有清理,却在上层覆盖空数据的界面。
求楼主解决一下,还有就是,我依赖的包不是最新的,楼主可以试试最新包有没有这种问题出现!

好像只有swiperefreshlayout会出现这种问题,其它的刷新框架没有问题!