Android 水平嵌套的recyclerviews在垂直父级中加载奇怪的信息

Android 水平嵌套的recyclerviews在垂直父级中加载奇怪的信息,android,android-recyclerview,Android,Android Recyclerview,一周来,我一直在尝试在一个垂直的recyclerview(父视图)中包含的一些水平的recyclerview中加载项目。两者都需要在下降时无休止地向右滚动水平方向和垂直方向 现在,无休止的滚动和加载工作。但是,这并不能正常工作,因为水平视图正在加载来自其他子对象的疯狂数据(我猜我是在ViewHolder中创建了Presenter,并且一些数据是如何混淆的) 有没有其他方法可以做到这一点。这可能比我的方法更好更快。此外,我还注意到,垂直加载并不像我在其他一些应用程序中看到的那样平滑 任何帮助都将不

一周来,我一直在尝试在一个垂直的recyclerview(父视图)中包含的一些水平的recyclerview中加载项目。两者都需要在下降时无休止地向右滚动水平方向和垂直方向

现在,无休止的滚动和加载工作。但是,这并不能正常工作,因为水平视图正在加载来自其他子对象的疯狂数据(我猜我是在ViewHolder中创建了Presenter,并且一些数据是如何混淆的)

有没有其他方法可以做到这一点。这可能比我的方法更好更快。此外,我还注意到,垂直加载并不像我在其他一些应用程序中看到的那样平滑

任何帮助都将不胜感激

class EventCatalogAdapter(private val presenter: EventCatalogPresenter):
        RecyclerView.Adapter<EventCatalogAdapter.ViewHolder>() {

    override fun getItemCount() = presenter.getCategoryEventCount()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
            EventCatalogAdapter.ViewHolder(parent.inflate(R.layout.item_event_catalog), viewType)

    override fun onBindViewHolder(holder: ViewHolder, position: Int) =
            presenter.bind(holder, position)

    override fun getItemViewType(position: Int) = presenter.getItemType(position)

    class ViewHolder(itemView: View, type: Int): RecyclerView.ViewHolder(itemView),
            EventCatalogItemView, EventViewList, OnItemClickListener<Event>,
            EndlessScrollListener.DataLoader {

        private lateinit var companyId: String
        private lateinit var catId: String
        private val eventPresenter = EventPresenterImpl(this)

        override val titleFormat: String? get() = ""

        init {
            val layoutManager = HorizontalLinearLayoutManager(itemView.context,
                    LinearLayoutManager.HORIZONTAL, false)
            itemView.rvEvents.layoutManager = layoutManager
            itemView.rvEvents.addItemDecoration(HorizontalItemDecorator(itemView.context))
            itemView.rvEvents.adapter = EventAdapter(eventPresenter, type, this)
            itemView.rvEvents.addOnScrollListener(EndlessScrollListener(layoutManager, this))
        }

        override fun setTitleVisibility(b: Boolean) {
            itemView.tvCategoryTitle.visibility = if(!b) View.GONE else View.VISIBLE
        }

        override fun setCategoryTitle(title: String) {
            itemView.tvCategoryTitle.text = title
        }

        override fun eventsByCategory(companyId: String, categoryId: String) {
            this.companyId = companyId
            catId = categoryId
            eventPresenter.getEventsByCategories(companyId, categoryId)
        }

        override fun loadMoreData(totalItems: Int) {
            Log.d("LOAD", "Event presenter: $eventPresenter for category: $catId")
            eventPresenter.getMoreEventsByCategories(companyId, catId, totalItems)
        }

        override fun setActiveEvent(event: Event?) {}

        override fun showSettings() {}

        override fun sendMessage(action: String, bundle: Bundle?) {}

        override fun showStatus(status: Int) {}

        override fun refresh() {
            itemView.rvEvents.adapter.notifyDataSetChanged()
        }

        override fun showMessageTemplate(code: Int) {}

        override fun hideMessageTemplate() {
            refresh()
        }

        override fun onItemClick(item: Event) {

        }

    }

}

class EventAdapter(private val presenter: EventPresenter,
                   private val listener: OnItemClickListener<Event>):
        RecyclerView.Adapter<EventAdapter.ViewHolderItemView>() {

    private var type: Int = EVENT_STANDARD

    constructor(presenter: EventPresenter, type: Int, listener: OnItemClickListener<Event>) :
            this(presenter, listener) {
        this.type = type
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
            ViewHolderItemView(parent.inflate(type))

    override fun onBindViewHolder(holder: ViewHolderItemView, position: Int) =
            presenter.bind(holder, position)

    override fun getItemCount() = presenter.getCount()

    class ViewHolderItemView(itemView: View) : RecyclerView.ViewHolder(itemView), EventItemView {

        override fun setEventDate(date: Date?) {
            itemView.tvDate.text = Tools.formatDate(itemView.context, date)
        }

        override fun setName(name: String) {
            itemView.tvName.text = name
        }

        override fun setScannerVisibility(scannerVisibility: Boolean) {
            itemView.ibScanner.visibility = if (scannerVisibility) View.VISIBLE else View.INVISIBLE
        }

        override fun setEventPoster(posterUrl: String, transformation: Transformation?) {
            Tools.loadImage(posterUrl, itemView.ivPoster, transformation, R.mipmap.portrait_test)
        }

        override fun setTotalRegistrants(totalRegistrants: Long) {
            itemView.tvQtyRegs.text = totalRegistrants.toString()
        }

        override fun addScanAction(event: Event) {
            itemView.ibScanner.setOnClickListener {
                val auth = FirebaseAuth.getInstance()
                val prefs = PreferenceHelper.customPrefs(itemView.context, auth.currentUser!!.uid)
                prefs.edit().putString(EventInteractorImpl.FIELD_EVENT_ID, event.eventId).apply()
                (itemView.context as SettingsActivity).launchScanner()
            }
        }

        override fun addEventAction(event: Event) {
            itemView.setOnClickListener {
                (itemView.context as SettingsActivity).showRegistrants(event)
            }
        }

    }

}

// Parent items:

<android.support.constraint.ConstraintLayout
    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="220dp">

    <TextView
        android:id="@+id/tvCategoryTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/vertical_spacing"
        android:paddingBottom="@dimen/vertical_spacing"
        android:layout_marginEnd="@dimen/horizontal_spacing"
        android:layout_marginStart="@dimen/horizontal_spacing"
        android:textAlignment="center"
        android:textSize="18sp"
        android:textAllCaps="true"
        android:fontFamily="sans-serif-light"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="@string/txt_cat_title" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvEvents"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginBottom="@dimen/vertical_spacing"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tvCategoryTitle" />

</android.support.constraint.ConstraintLayout>

// Children items

<android.support.constraint.ConstraintLayout
    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="110dp"
    android:layout_height="match_parent"
    android:stateListAnimator="@animator/tile_elevation">

        <ImageView
            android:id="@+id/ivPoster"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:contentDescription="@string/txt_event_image"
            android:src="@mipmap/portrait_test"
            android:scaleType="centerCrop"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/tvName"
            style="@style/SubTitle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textIsSelectable="false"
            android:textAllCaps="true"
            app:layout_constraintBottom_toTopOf="@+id/ibRegistrants"
            app:layout_constraintStart_toStartOf="@+id/ibRegistrants"
            tools:text="Washington D.C. " />

        <TextView
            android:id="@+id/tvDate"
            style="@style/SubTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textIsSelectable="false"
            app:layout_constraintBottom_toTopOf="@+id/tvName"
            app:layout_constraintStart_toStartOf="@+id/ibRegistrants"
            tools:text="03/23" />

        <TextView
            android:id="@+id/tvQtyRegs"
            style="@style/Title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:textIsSelectable="false"
            app:layout_constraintBottom_toBottomOf="@+id/ibRegistrants"
            app:layout_constraintStart_toEndOf="@+id/ibRegistrants"
            app:layout_constraintTop_toTopOf="@+id/ibRegistrants"
            tools:text="140" />

        <ImageView
            android:id="@+id/ibRegistrants"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginStart="8dp"
            android:contentDescription="@string/txt_registrants"
            android:src="@drawable/ic_registrants_48px"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

        <ImageButton
            android:id="@+id/ibScanner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:contentDescription="@string/txt_registrants"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/ic_scan_action" />

</android.support.constraint.ConstraintLayout>
class EventCatalogAdapter(专用val演示者:EventCatalogPresenter):
RecyclerView.Adapter(){
覆盖有趣的getItemCount()=presenter.getCategoryEventCount()
重写CreateViewHolder(父级:ViewGroup,viewType:Int)=
EventCatalogAdapter.ViewHolder(父级充气(R.layout.item\u事件\u目录),viewType)
覆盖BindViewHolder(holder:ViewHolder,位置:Int)=
演示者绑定(持有者、位置)
覆盖有趣的getItemViewType(位置:Int)=presenter.getItemType(位置)
类ViewHolder(itemView:View,type:Int):RecyclerView.ViewHolder(itemView),
EventCatalogItemView、EventViewList、OnItemClickListener、,
EndlessCrollListener.DataLoader{
私有lateinit var companyId:字符串
私有lateinit var catId:字符串
private val eventPresenter=EventPresenterImpl(此)
覆盖val标题格式:字符串?get()=“”
初始化{
val layoutManager=HorizontalLinearLayoutManager(itemView.context,
LinearLayoutManager.HORIZONTAL,false)
itemView.rvEvents.layoutManager=layoutManager
itemView.rvEvents.addItemDecoration(HorizontalitItemDecorator(itemView.context))
itemView.rvEvents.adapter=EventAdapter(eventPresenter,类型,此)
itemView.rvEvents.addOnScrollListener(EndlessScrollListener(layoutManager,此))
}
覆盖乐趣设置可选项(b:布尔值){
itemView.tvCategoryTitle.visibility=如果(!b)View.GONE else View.VISIBLE
}
覆盖有趣的setCategoryTitle(标题:字符串){
itemView.tvCategoryTitle.text=标题
}
覆盖有趣的事件ByCategory(companyId:String,categoryId:String){
this.companyId=companyId
catId=类别ID
eventPresenter.getEventsByCategories(公司ID,类别ID)
}
覆盖数据(totalItems:Int){
Log.d(“加载”,“事件演示者:$eventPresenter,类别:$catId”)
eventPresenter.getMoreEventsByCategories(公司ID、catId、totalItems)
}
重写有趣的setActiveEvent(事件:事件?{}
覆盖有趣的showSettings(){}
重写消息(操作:字符串,捆绑:捆绑?{}
覆盖状态(状态:Int){}
覆盖乐趣刷新(){
itemView.rvEvents.adapter.notifyDataSetChanged()
}
重写showMessageTemplate(代码:Int){}
覆盖有趣的hideMessageTemplate(){
刷新()
}
重写MClick(项目:事件){
}
}
}
类EventAdapter(私有val presenter:EventPresenter,
专用val侦听器:MCL侦听器):
RecyclerView.Adapter(){
私有变量类型:Int=EVENT\u标准
构造函数(presenter:EventPresenter,类型:Int,侦听器:OnItemClickListener):
此(演示者、听众){
this.type=type
}
重写CreateViewHolder(父级:ViewGroup,viewType:Int)=
ViewHolderItemView(父级充气(类型))
覆盖BindViewHolder(holder:ViewHolderItemView,位置:Int)=
演示者绑定(持有者、位置)
重写getItemCount()=presenter.getCount()
类ViewHolderItemView(itemView:View):RecyclerView.ViewHolder(itemView),EventItemView{
覆盖设置事件日期(日期:日期?){
itemView.tvDate.text=Tools.formatDate(itemView.context,date)
}
覆盖乐趣集名称(名称:字符串){
itemView.tvName.text=名称
}
覆盖可扫描性(扫描可视性:布尔值){
itemView.ibScanner.visibility=if(scannerVisibility)View.VISIBLE else View.INVISIBLE
}
重写有趣的setEventPoster(posterUrl:String,transformation:transformation?){
Tools.loadImage(posterUrl、itemView.ivPoster、transformation、R.mipmap.portrait_测试)
}
覆盖有趣的设置totalRegistrants(totalRegistrants:长){
itemView.tvQtyRegs.text=totalregisters.toString()
}
重写操作(事件:事件){
itemView.ibScanner.setOnClickListener{
val auth=FirebaseAuth.getInstance()
val prefs=PreferenceHelper.customPrefs(itemView.context,auth.currentUser!!.uid)
prefs.edit().putString(eventinteractitorimpl.FIELD\u EVENT\u ID,EVENT.eventId).apply()
(itemView.context作为SettingsActivity).launchScanner()
}
}
覆盖趣味addEventAction(事件:事件){
itemView.setOnClickListener{
(itemView.context作为设置活动)。显示注册者(事件)
}
}
}
}
//父项:
//儿童用品

您能为水平和垂直recycleview发布布局文件和recycleview适配器类吗?您从哪里获得数据到recycleview?来自api?@Harshai我正在从云存储Fireins获取数据