如何在NestedScrollView中为RecyclerView使用FirestorePagingAdapter

时间:2018-07-25 12:55:06

标签: android google-cloud-firestore recycler-adapter firebaseui android-nestedscrollview

我正在使用FirestorePagingAdapter从Firestore提取文档。一切都很完美,但是“加载更多”会自动发生,而不会到达列表的底部。这导致了不良行为。

我已将RecyclerView(高度:包装内容)放在NestedScrollView(高度:match-parent)中,这是我的主要滚动活动布局的内容。

只有当我滚动到最后一个项目时,才可以加载更多项目。

<android.support.v4.widget.NestedScrollView 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".NewLookCode.activities.MainScrollingActivity"
tools:showIn="@layout/activity_main_scrolling">

    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="match_parent">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv_transporters"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:nestedScrollingEnabled="false"
                android:padding="10dp"
                android:visibility="visible" />

    </LinearLayout>

 val baseQuery = FirebaseFirestore.getInstance().collection("partners")
    val config = PagedList.Config.Builder()
            .setEnablePlaceholders(true)
            .setPrefetchDistance(2)
            .setPageSize(6)
            .build()

    val options = FirestorePagingOptions.Builder<PartnerInfoPojo>()
            .setLifecycleOwner(this)
            .setQuery(baseQuery, config, PartnerInfoPojo::class.java)
            .build()
    adapter = object:FirestorePagingAdapter<PartnerInfoPojo, PartnersViewHolder>(options) {
        @NonNull
        override fun onCreateViewHolder(@NonNull parent: ViewGroup, viewType:Int):PartnersViewHolder {
            val view = LayoutInflater.from(parent.context)
                    .inflate(R.layout.item_new_transporter, parent, false)
            return PartnersViewHolder(view)
        }

        override fun onBindViewHolder(@NonNull holder:PartnersViewHolder,
                                      position:Int,
                                      @NonNull model:PartnerInfoPojo) {
                holder.mCompany.text = model.getmCompanyName()

            if(model!=null){
                if(model.getmCompanyAdderss()!=null)
                    holder.mAddress.text = model.getmCompanyAdderss().city
            }


        }

    }

    rv_transporters.layoutManager = LinearLayoutManager(this)
    rv_transporters.adapter = adapter

0 个答案:

没有答案