RecyclerView-RecyclerView中缺少我的数据之一

时间:2018-12-13 12:01:12

标签: android

这很奇怪。我为这个问题感到沮丧。我将数据保存在ArrayList中。当我将数据放在RecyclerView上时。数据未显示在列表中。这是我的密码

listOrder.forEach { order ->

                        Log.e(APPConfigs.LOG_TAG,"${order.status} == ${APPConfigs.STATUS_ORDER_BELUM_SIAP}")

                        if(order.status == APPConfigs.STATUS_ORDER_BELUM_SIAP){

                            Log.e(APPConfigs.LOG_TAG," Check : ${order.nama_pemesan}  email : ${order.email_pemesan}")

                            temp.add(order)
                        }

                    }

                    Log.e(APPConfigs.LOG_TAG,"Ready Active Order : temp.size : ${temp.size}")

                    initListOrderAdapter(temp)

该代码生成此日志:

BELUM SIAP == BELUM SIAP
2018-12-13 18:51:53.244 4495-4495/galihlprakoso.com.pawonkumerchant E/PAWONKU:  Check : Tony Solala  email : galihlarasprakoso_gmail_com
2018-12-13 18:51:53.244 4495-4495/galihlprakoso.com.pawonkumerchant E/PAWONKU: BELUM SIAP == BELUM SIAP
2018-12-13 18:51:53.244 4495-4495/galihlprakoso.com.pawonkumerchant E/PAWONKU:  Check : Tony Solala  email : galihlarasprakoso_gmail_com
2018-12-13 18:51:53.244 4495-4495/galihlprakoso.com.pawonkumerchant E/PAWONKU: BELUM SIAP == BELUM SIAP
2018-12-13 18:51:53.245 4495-4495/galihlprakoso.com.pawonkumerchant E/PAWONKU:  Check : Tony Solala  email : galihlarasprakoso_gmail_com
2018-12-13 18:51:53.245 4495-4495/galihlprakoso.com.pawonkumerchant E/PAWONKU: BELUM SIAP == BELUM SIAP
2018-12-13 18:51:53.245 4495-4495/galihlprakoso.com.pawonkumerchant E/PAWONKU:  Check : Kidalist  email : jn5990_gmail_com
2018-12-13 18:51:53.245 4495-4495/galihlprakoso.com.pawonkumerchant E/PAWONKU: Ready Active Order : temp.size : 4

它说我的临时变量大小是:4。

这是我的RecyclerViewAdapter代码:

binding.listOrder.adapter = RecyclerViewAdapter<Order,ItemOrderBinding>(listOrders,
                R.layout.item_order, BR.order){ itemOrderBinding ->

            Log.e(APPConfigs.LOG_TAG," Check2 : ${itemOrderBinding.order!!.nama_pemesan}  email : ${itemOrderBinding.order!!.email_pemesan}")

它产生此日志:

Check2 : Tony Solala  email : galihlarasprakoso_gmail_com
2018-12-13 18:51:53.549 4495-4495/galihlprakoso.com.pawonkumerchant E/PAWONKU:  Check2 : Tony Solala  email : galihlarasprakoso_gmail_com
2018-12-13 18:51:53.686 4495-4495/galihlprakoso.com.pawonkumerchant E/PAWONKU:  Check2 : Tony Solala  email : galihlarasprakoso_gmail_com

只有3个?什么? RecyclerView中会发生什么。我自己的MyRecyclerViewAdapter可以很好地使用“其他”数据。这是MyRecyclerViewAdapter:

package galihlprakoso.com.pawonkumerchant.app.adapter

import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup

class RecyclerViewAdapter<T,B:ViewDataBinding>(var list: List<T>,
                                               val layout_id:Int,
                                               val variable_id:Int,
                                               val onBind:(B)->Unit) : RecyclerView.Adapter<RecyclerViewAdapter<T,B>.RecyclerViewHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewHolder {
        val binding = DataBindingUtil.inflate<B>(LayoutInflater.from(parent.context),
                layout_id,parent,false)


        return RecyclerViewHolder(binding)
    }

    override fun onBindViewHolder(holder: RecyclerViewHolder,position:Int){

        holder.binding.setVariable(variable_id,list[position])

        onBind(holder.binding)

    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemCount(): Int {
        return list.size
    }



    inner class RecyclerViewHolder(internal var binding: B) : RecyclerView.ViewHolder(binding.root)

}

请。救命。谢谢!

1 个答案:

答案 0 :(得分:0)

已解决。问题出在ScrollView上。我将RecyclerView放在ScrollView中。

此堆栈解决了我的问题: RecyclerView inside ScrollView, some items are not shown