Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在完成滚动后访问recyclerView中的特定视图/视图持有者?_Android - Fatal编程技术网

Android 如何在完成滚动后访问recyclerView中的特定视图/视图持有者?

Android 如何在完成滚动后访问recyclerView中的特定视图/视图持有者?,android,Android,将此行替换为findViewHolderForAdapterPosition,但当我滚动并单击recycler视图中的最后一个视图时,仍然会出现空指针异常 var expandedView:View=SavedNotificationActivityV2.rv\u notificationList!!。GetChildateExpandedPos Every thing works fine if i m not scrolling , if i scroll i get null pointe

将此行替换为findViewHolderForAdapterPosition,但当我滚动并单击recycler视图中的最后一个视图时,仍然会出现空指针异常 var expandedView:View=SavedNotificationActivityV2.rv\u notificationList!!。GetChildateExpandedPos

Every thing works fine if i m not scrolling , if i scroll i get null pointer exception. I tried using getchildAt(position) and findViewHolderForAdapterPosition(position) basically i m getting the view at this position to expand the view, after scrolling on click of that view it throws null pointer exception.

Basically getChildAt and findViewHolderForAdapterPosition is null after scroll in android

 My requirement is on click of any view the view should be expanded and on click of same view view should be close and same if one view is clicked and if clicking on other view the view which was already expanded/open should be close and open the clicked view.

How to achieve all case in recycler view?

I have pojo and pojo contains one of the variable as isread boolean (true/false)

Any help is appreciated!

Below is the code:

holder.card_view_layer.setOnClickListener {
                if (position != expandedPos && expandedPos != -1) {
                    notificationPojoList[expandedPos].isRead = true
                    var expandedView  :View = SavedNotificationActivityV2.rv_notificationList!!.getChildAt(expandedPos)
                    var expandedMsg:TextView = expandedView.findViewById(R.id.tv_message)
                    var expandedIsRead:View = expandedView.findViewById(R.id.view_isRead)
                    expandedIsRead.setBackgroundColor(context.resources.getColor(R.color.surya_read_notif_grey))
                    expandedMsg.visibility = View.GONE
                    expandedIsRead.visibility = View.VISIBLE

                    holder.message.visibility = View.VISIBLE
                    holder.view_isRead.visibility = View.INVISIBLE
                    expandedPos = position
                } else {
                    if (holder.message.visibility == View.VISIBLE) {
                        expandedPos = -1
                        holder.message.visibility = View.GONE
                        holder.view_isRead.visibility = View.VISIBLE
                        holder.view_isRead.setBackgroundColor(context.resources.getColor(R.color.colorAccent))
                        notificationPojoList[position].isRead = true
                        (context as SavedNotificationActivityV2).updategui()
                    } else {
                        holder.message.visibility = View.VISIBLE
                        holder.view_isRead.visibility = View.INVISIBLE
                        notificationPojoList[position].isRead = true
                        expandedPos = position
                    }
                }
            }

您应该在这里发布代码,以便可以看到问题发布代码plz check如果您有模型,则从模型中读取值,以检查其是否在onBindViewHolder中展开,并相应地显示视图。并在模型中单击视图更新值。并调用notifyDataSetChanged。视图将根据模型中的新数据重新绘制。我的要求是当一个视图显示给用户时,如果用户展开另一个视图,则应关闭第一个视图。您可以粘贴一些代码吗?
Any help is appreciated!
    I myself found solution to above question.Please find the code below:
if(position == lastPos){
                    holder.message.visibility = View.VISIBLE
                }else{
                    holder.message.visibility = View.GONE
                }
                holder.itemView.setOnClickListener(){
                    if(lastPos == position){
                        holder.message.visibility = View.GONE
                        lastPos = -1
                    }else {
                        lastPos = position;
                        notifyDataSetChanged()
                    }

                }