RecyclerView在调用notifyItemInserted和notifyItemRangeChanged

时间:2018-10-20 14:52:22

标签: android android-recyclerview recycler-adapter recyclerview-layout

我的RecyclerView带有动态内容,例如可以添加和删除,但是还可以,但是有一天像这样,它变得很臭而且很奇怪。

enter image description here

使用上个月的notifyItemInserted()和notifyItemRangeChanged()来更新列表的情况很好。我还尝试将依赖项更新为28.0.0,但无法正常工作。这只是一个带有RecyclerView的活动。我仍然无法弄清楚,因为那时还没有发生。

这是我的XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDarker"
tools:context=".common.AnnouncementComments"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/commentLinear"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:minHeight="?android:attr/actionBarSize"
        android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        tools:targetApi="lollipop">


        <TextView
            android:id="@+id/titleBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/comment_section"
            android:textColor="@color/icon_selected"
            android:textSize="24sp"
            android:textStyle="bold"
            android:typeface="normal" />

    </android.support.v7.widget.Toolbar>


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.yalantis.phoenix.PullToRefreshView
            android:id="@+id/comment_refresh"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="2dp">

            <com.bitwise.rotaractclubapp.system.AutoPlayVideoRecyclerView
                android:id="@+id/commentRecycler"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="3dp" />

            </com.yalantis.phoenix.PullToRefreshView>

        <TextView
            android:id="@+id/noComments"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/be_the_first_in_this_comment_section"
            android:textColor="@color/not_selected"
            android:layout_centerInParent="true"
            android:textSize="18sp" />
    </RelativeLayout>

</LinearLayout>

<LinearLayout
    android:id="@+id/commentLinear"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="@color/colorPrimaryDark"
        android:padding="5dp"
        android:weightSum="10">

        <com.sackcentury.shinebuttonlib.ShineButton
            android:id="@+id/videoBtn"
            android:layout_width="30dp"
            android:layout_height="35dp"
            android:layout_gravity="center"
            android:layout_marginEnd="5dp"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:contentDescription="@string/help"
            app:allow_random_color="true"
            app:big_shine_color="@color/highlighted"
            app:click_animation_duration="350"
            app:enable_flashing="true"
            app:shine_animation_duration="5000"
            app:shine_count="15"
            app:shine_turn_angle="20"
            app:siShape="@drawable/ic_movie_creation_black_24dp"
            app:small_shine_offset_angle="40"
            app:srcCompat="@drawable/ic_movie_creation_black_24dp"
            app:tint="@color/highlighted" />


        <com.sackcentury.shinebuttonlib.ShineButton
            android:id="@+id/imageBtn"
            android:layout_width="30dp"
            android:layout_height="35dp"
            android:layout_gravity="center"
            android:layout_marginEnd="5dp"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:contentDescription="@string/help"
            app:allow_random_color="true"
            app:big_shine_color="@color/highlighted"
            app:click_animation_duration="350"
            app:enable_flashing="true"
            app:shine_animation_duration="5000"
            app:shine_count="15"
            app:shine_turn_angle="20"
            app:siShape="@drawable/ic_image_black_24dp"
            app:small_shine_offset_angle="40"
            app:srcCompat="@drawable/ic_image_black_24dp"
            app:tint="@color/highlighted" />

        <EditText
            android:id="@+id/comment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="7"
            android:background="@drawable/edit_text_background"
            android:ems="10"
            android:hint="@string/your_comment"
            android:inputType="text|textCapSentences|textMultiLine"
            android:padding="10dp"
            android:textColor="@color/icon_selected"
            android:textColorHint="@color/icon_not_selected"
            tools:targetApi="lollipop"
            tools:ignore="Autofill" />

        <com.sackcentury.shinebuttonlib.ShineButton
            android:id="@+id/sendingBtn"
            android:layout_width="30dp"
            android:layout_height="35dp"
            android:layout_gravity="center"
            android:layout_marginStart="5dp"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:contentDescription="@string/help"
            app:allow_random_color="true"
            app:big_shine_color="@color/highlighted"
            app:click_animation_duration="350"
            app:enable_flashing="true"
            app:shine_animation_duration="5000"
            app:shine_count="15"
            app:shine_turn_angle="20"
            app:siShape="@drawable/ic_send_white_24dp"
            app:small_shine_offset_angle="40"
            app:srcCompat="@drawable/ic_send_white_24dp"
            app:tint="@color/highlighted" />

    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/filesRecycler"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        android:layout_marginBottom="2dp"
        android:layout_marginStart="2dp"
        android:visibility="gone" />

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

我解决了一个愚蠢的错误,花了我数周的时间才弄清楚。 问题的原因是声明某些商品不可回收setIsRecyclable(false)