XRecyclerView 适配不显示数据

采用框架:xdroidmvp

适配了adapter但却不会显示数据,看有问题的代码:
拿到数据之后做的适配

adapter = new PoiSearchAdapter(this, listdata);
listAroundpoi.setAdapter(adapter);

修改后的代码:

 adapter = new PoiSearchAdapter(this);
 listAroundpoi.setAdapter(adapter);
...
adapter.addData(listdata);

主要修改点在于:adapter的构造方法不需要传递listdata数据,而是有数据了之后再addData()即可,可能也是XRecyclerView 优化点之一吧,我把adapter的代码全部贴出来:

public class PoiSearchAdapter extends SimpleRecAdapter {

String TAG="PoiSearchAdapter";
Context mContext;

public PoiSearchAdapter(Context context) {
    super(context);
    this.mContext = context;
}

@Override
public ViewHolder newViewHolder(View itemView) {
    return new ViewHolder(itemView);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    PoiItem poi = data.get(position);
    holder.tvAddress.setText(poi.getAdName());
    Log.e(TAG,"poi.getAdName()="+poi.getAdName());
}

@Override
public int getLayoutId() {
    return R.layout.view_listview_poi;
}

public static class ViewHolder extends RecyclerView.ViewHolder {

    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.iv_state)
    ImageView ivState;

    public ViewHolder(View itemView) {
        super(itemView);
        KnifeKit.bind(this, itemView);
    }
}
}

你可能感兴趣的:(XRecyclerView 适配不显示数据)