RecyclerView,ListView等会用到Adapter并复用Item时already has a parent的错误

备战一夜竟然只是这么一个小错误,还是太年轻啊,毕竟刚学,最终是在

http://stackoverflow.com/questions/26596436/error-using-the-recyclerview-the-specified-child-already-has-a-parent

找到解决方法的,记录一下,免得再犯

Adapter里创建Item的时候 LayouInflater.inflater();一定要选三个参数的,一定要选三个参数的,一定要选三个参数的。且第三个参数一定要为false,要不然嘛,Item都与根视图绑定了还复用回收个毛坐等BUG

public class PiliAdapter extends RecyclerView.Adapter {
    ArrayList piliList;
    Context mContext;
    private static final String TAG = "PiliAdapter";

    public PiliAdapter(ArrayList piliList, Context mContext) {
        this.piliList = new ArrayList<>();
        this.piliList.addAll(piliList);
        this.mContext = mContext;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View layout = LayoutInflater.from(mContext).inflate(R.layout.view_pili_new, parent,false);
        return new MyHolder(layout);
    }

你可能感兴趣的:(Apapter)