回收器适配器显示"您必须首先在孩子的父母上调用removeView()"错误

时间:2017-05-30 05:48:38

标签: android

我已经制作了一个recyclerview适配器,我在recyclerview中展示了很多东西。我也在viewpager的视图中显示一些图像。它的工作正常,但是当我为viewpager指示器添加viewPagerArrowIndicator库时,它在我从上往上滚动回来时显示上面的错误。 我尝试过使用stackoverflow的解决方案,但没有类似的错误或解决方案

logcat的:

Process: com.systechdigital.webadeal, PID: 30287
                  java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
                      at android.view.ViewGroup.addViewInner(ViewGroup.java:4659)
                      at android.view.ViewGroup.addView(ViewGroup.java:4495)
                      at android.view.ViewGroup.addView(ViewGroup.java:4436)
                      at android.view.ViewGroup.addView(ViewGroup.java:4409)
                      at com.sembozdemir.viewpagerarrowindicator.library.ViewPagerArrowIndicator.arrange(ViewPagerArrowIndicator.java:107)
                      at com.sembozdemir.viewpagerarrowindicator.library.ViewPagerArrowIndicator.bind(ViewPagerArrowIndicator.java:82)
                      at com.systechdigital.webadeal.NewsFeedAdapter.onBindViewHolder(NewsFeedAdapter.java:197)
                      at com.systechdigital.webadeal.NewsFeedAdapter.onBindViewHolder(NewsFeedAdapter.java:38)
                      at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6310)
                      at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6343)
                      at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5289)
                      at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5552)
                      at android.support.v7.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:270)
                      at android.support.v7.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:324)
                      at android.support.v7.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:337)
                      at android.support.v7.widget.GapWorker.prefetch(GapWorker.java:344)
                      at android.support.v7.widget.GapWorker.run(GapWorker.java:370)
                      at android.os.Handler.handleCallback(Handler.java:739)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:7325)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

我的适配器代码:

        //image slider
        if(newsFeedClassArrayList.get(position).getImageList()!=null){

            holder.viewPager.setVisibility(View.VISIBLE);
            viewPagerAdapter=new ViewPagerAdapter(context,newsFeedClassArrayList.get(position).getImageList());
            holder.viewPager.setAdapter(viewPagerAdapter);


**//error showing below on line**
            holder.viewPagerArrowIndicator.bind(holder.viewPager);
            holder.viewPagerArrowIndicator.setArrowIndicatorRes(R.drawable.arrow_left_black_24dp,R.drawable.arrow_right_black_24dp);

            viewPagerAdapter.notifyDataSetChanged();

        }else {
            holder.viewPager.setVisibility(View.GONE);
        }

        holder.timeStampTvId.setText(newsFeedClass.getTimeStamp());

xml代码:

<com.sembozdemir.viewpagerarrowindicator.library.ViewPagerArrowIndicator
        android:id="@+id/viewPagerArrowIndicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    <android.support.v4.view.ViewPager
        android:layout_width="wrap_content"
        android:layout_height="180dp"
        android:id="@+id/viewPagerId_imageView"
        android:minHeight="0dp"
        >
    </android.support.v4.view.ViewPager>

    </com.sembozdemir.viewpagerarrowindicator.library.ViewPagerArrowIndicator>

1 个答案:

答案 0 :(得分:0)

尝试使用其他库,即使您不想使用它只是用它来进行测试。

也许你可以试试这个 - https://github.com/ongakuer/CircleIndicator