简体   繁体   English

Scrollview内部的Recyclerview未调用自定义适配器函数(onBindViewHolder)

[英]Recyclerview inside a Scrollview not calling the Custom Adapter Function (onBindViewHolder)

While scrolling the page, onBindViewHolder() is not calling. 在滚动页面时,onBindViewHolder()没有调用。

mAdapter.notifyDataSetChanged() is not updating the data correctly because of Scrollview. 由于Scrollview,mAdapter.notifyDataSetChanged()未正确更新数据。 I checked only 3 Checkbox in Recycler. 我在Recycler中只检查了3个Checkbox。 After the loading of 2nd set of data and calling the notifier more checkbox got checked irrelevantly still the data is coming from Model class correctly. 在加载第二组数据并调用通知程序后,更多的复选框被无关紧密地检查,数据仍然正确地来自Model类。

I can't share the code here, because of security reasons. 出于安全原因,我无法在此处共享代码。 I already spent a day to fix. 我已经花了一天时间来解决问题。 Not fixed yet. 尚未修复。

Then I tried removing the scrollview, it worked. 然后我尝试删除scrollview,它工作。

I have another few more view to fit inside the scroller. 我还有另外几个视图适合滚动条。 So I added that as a layout and added in the first position of Recycler. 所以我添加了作为布局并添加到Recycler的第一个位置。 It worked. 有效。 But from fragment whenever I want only that time it should come. 但是,只要我想要那个时候就应该来自片段。 Is there any way to fix atleast this way. 有没有办法解决至少这种方式。

I think you should replace ScrollView with android.support.v4.widget.NestedScrollView 我认为你应该用android.support.v4.widget.NestedScrollView替换ScrollView

for example: 例如:

<?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true" >

    <android.support.design.widget.AppBarLayout
                android:id="@+id/app_bar"
                android:layout_width="match_parent"
                android:layout_height="@dimen/app_bar_height"
                android:fitsSystemWindows="true"
                android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:layout_collapseMode="pin"
                        app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" >

    <!-- Place RecyclerView in here-->

    </android.support.v4.widget.NestedScrollView>

    </android.support.design.widget.CoordinatorLayout>

@Ogande, Thanks. @Ogande,谢谢。 I tried your code. 我试过你的代码。 Same thing is happening. 同样的事情正在发生。 So I tried with different solution, as I mentioned in my question. 所以我尝试了不同的解决方案,正如我在问题中提到的那样。

I removed the scrollview and kept only Recyclerview. 我删除了scrollview并只保留了Recyclerview。

I added two layouts in my Adapter. 我在适配器中添加了两个布局。 So whenever I want to add the new layout I am passing a boolean value from the fragment to the adapter as true and at the starting all the position will take default value as false. 因此,每当我想添加新布局时,我将片段中的布尔值传递给适配器为true,并且在开始时所有位置都将默认值设置为false。 So notifychanged() will reflect the change to the adapter with that new layout. 因此notifychanged()将反映对该新布局的适配器的更改。

It worked nicely as I expected. 它按照我的预期很好地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用RecyclerView.Adapter在onBindViewHolder()内设置onItemClickListener - Set onItemClickListener inside onBindViewHolder() with RecyclerView.Adapter 如何在RecyclerView适配器的onBindViewHolder中声明overridePendingTransition? - How to declare overridePendingTransition inside onBindViewHolder of a RecyclerView adapter? RecyclerView适配器:OnBindViewHolder - RecyclerView Adapter :OnBindViewHolder Firebase RecyclerView Adapter onBindViewHolder - Firebase RecyclerView Adapter onBindViewHolder 如何在其适配器的onBindViewHolder中更新recyclerView? - How do I update recyclerView inside onBindViewHolder of its adapter? 从 RecyclerViewAdapter 启动BottomSheet,它在onBindViewHolder 内扩展了RecyclerView.Adapter - Launching BottomSheet from a RecyclerViewAdapter that extends with RecyclerView.Adapter inside onBindViewHolder OnCreate和Onbindviewholder未调用recyclerview - OnCreate and Onbindviewholder is not calling on recyclerview Recyclerview 适配器 onBindViewHolder 有效负载不起作用 - Recyclerview adapter onBindViewHolder payload is not working 在 RecyclerView 适配器的 onBindViewHolder 中获取上下文 - Get context in onBindViewHolder in RecyclerView Adapter RecyclerVIew适配器onBIndVIewHolder中的上下文错误 - context error in RecyclerVIew Adapter onBIndVIewHolder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM