RecyclerView The specified child already has a parent

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wuzhong8809/article/details/78384709
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                   int viewType) {
        // create a new view
        Log.d(TAG, "onCreateViewHolder");
        RelativeLayout v = (RelativeLayout)LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_item, parent, false);
        // set the view's size, margins, paddings and layout parameters
        View view = v.findViewById(R.id.text1);
        v.removeView(view);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }

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

v.removeView() is not needed! Just pass v itself into ViewHolder constructor instead of view. And call findViewById() inside ViewHolder constructor. – goRGon Jul 29 '15 at 0:25 

猜你喜欢

转载自blog.csdn.net/wuzhong8809/article/details/78384709
今日推荐