Android 为什么RecyclerView适配器没有';在手动卷轴上是否立即初始化其项目?

Android 为什么RecyclerView适配器没有';在手动卷轴上是否立即初始化其项目?,android,drag-and-drop,android-recyclerview,Android,Drag And Drop,Android Recyclerview,我在对话中使用了2个RecyclerViews。其中一个RecyclerView在其中进一步使用嵌套列表。到目前为止一切正常(没有身高问题) 但是,从另一个RecyclerView中,我拖动了一个图像/视图,并在另一个RecyclerView中希望将其删除 此功能工作正常,但出现以下问题: 当拖动的图像使用DragListener的可用拖动事件进入该区域时,我通常会高亮显示特定的文本区域(请参见下图): 因此,如果我将图像拖到“Customer Voice 5”文本标题,它将高亮显示 当我将其

我在对话中使用了2个RecyclerViews。其中一个RecyclerView在其中进一步使用嵌套列表。到目前为止一切正常(没有身高问题)

但是,从另一个RecyclerView中,我拖动了一个图像/视图,并在另一个RecyclerView中希望将其删除

此功能工作正常,但出现以下问题:

当拖动的图像使用DragListener的可用拖动事件进入该区域时,我通常会高亮显示特定的文本区域(请参见下图):

因此,如果我将图像拖到“Customer Voice 5”文本标题,它将高亮显示

当我将其拖动到第5个项目时,它会向下滚动(如DragListener中使用
smoothScrollBy()
)编码的内容),第6个项目的标题“Customer Voice 6”文本标题也可见,但不会突出显示。它也不会进一步向下滚动以完全显示,此项上没有代码,就好像RecyclerView尚未在其onBindViewHolder(…)方法中更新/识别此项一样

现在,我将拖动的图像放到别处(无操作),然后再次将图像拖动到“Customer Header 6”,它会高亮显示!(还有滚动)这意味着在我第一次运行时丢弃图像后,RecyclerView已经对其进行了更新

因此,当我拖动时,拖动侦听器的事件操作\u拖动\u位置会持续运行,并且在发生这种情况时,Recycler视图似乎无法控制。那么,如何让DragListener和RecycleServiceAdapter这两个东西一起工作呢?[我知道RV如何使用支架上的物品,并在从脏视图列表看不见时重新使用]

我试着去改变;但是没有帮助。在这上面找不到其他东西。也许LinearLayoutManager可能会有所帮助,但无法将其与我的问题联系起来。下面是我的RV适配器的一些代码块

 @Override
    public void onBindViewHolder(MyHolder holder, int position) {


        Log.d("Log","OnBindViewHolder"+position);

        holder.customerVoiceTitle.setText(hashMap.get(position));  //Setting Header Text - "Customer Voice [position+1]"

        holder.customerVoiceTitle.setId(position + 100);   // Setting id to be able to detect each header while performing drag actions

        holder.customerVoiceTitle.setOnDragListener(new MyDragListener());

        customerVoiceMainHeaderText.setId(50);  //Neglect this for the time being, this is also a part of the issue.

        customerVoiceMainHeaderText.setOnDragListener(new MyDragListener());

        holder.totalWorkLayoutListView.setId(position + 150); //ListView also is utilized to perform drag actions

        holder.totalWorkLayoutListView.setOnDragListener(new MyDragListener());

        UtilityClass.setListViewHeightBasedOnChildren(holder.totalWorkLayoutListView, "", ""); //To avoid height inflation issues

      /*  if(allFlag) {
            customerVoiceWorkListCustomAdapter = new CustomerVoiceWorkListCustomAdapter(context, 5, true);
        }
        else if(!allFlag) {
            customerVoiceWorkListCustomAdapter = new CustomerVoiceWorkListCustomAdapter(context, 5, false);
        }*/

        holder.totalWorkLayoutListView.setAdapter(customerVoiceWorkListCustomAdapter);
    }




class MyDragListener implements View.OnDragListener {
        Drawable normalShape = context.getResources().getDrawable(R.drawable.bg_fragment_header_with_border);
        Drawable targetShape = context.getResources().getDrawable(R.drawable.target_shape);

        @Override
        public boolean onDrag(View v, DragEvent event) {


            // Handles each of the expected events
            switch (event.getAction()) {


                //signal for the start of a drag and drop operation.
                case DragEvent.ACTION_DRAG_STARTED:
                    // do nothing
                    break;

                //the drag point has entered the bounding box of the View
                case DragEvent.ACTION_DRAG_ENTERED:
                    if(v.getId() >= 100 && v.getId() < 150)  //For Header Text only
                    v.setBackground(targetShape);    //change the shape of the view
                    break;

                //the user has moved the drag shadow outside the bounding box of the View
                case DragEvent.ACTION_DRAG_EXITED:
                    if(v.getId() >= 100 && v.getId() < 150)  //For Header Text only
                    v.setBackground(normalShape);    //change the shape of the view back to normal
                    break;

                //drag shadow has been released,the drag point is within the bounding box of the View
                case DragEvent.ACTION_DROP:

                    Log.d("Log", "" + v.getId());
                    // if the view is the bottomlinear, we accept the drag item
                    if (v.getId() >= 100 && v.getId() < 150) {  //For Header Text only. If dragged image is dropped some changes take place inside the list. Not IMP now

                        TextView workListHeaderText = (TextView) v;
                        LinearLayout containerLayout = (LinearLayout) workListHeaderText.getParent();

                        ListView workLayoutList = (ListView) containerLayout.getChildAt(1);

                        customerVoiceWorkListCustomAdapter = new CustomerVoiceWorkListCustomAdapter(context, 5, true);

                        workLayoutList.setAdapter(customerVoiceWorkListCustomAdapter);

                    } else if (v.getId() == 50) {
                        allFlag = true;
                        TextView workListRootHeaderText = (TextView) v;
                        LinearLayout layout = (LinearLayout) workListRootHeaderText.getParent();

                        RecyclerView technicianAllotment = (RecyclerView) layout.getChildAt(1);

                        int childCount = technicianAllotment.getChildCount();


                        for (int listCount = 0; listCount < childCount; listCount++) {
                            LinearLayout linearLayout = (LinearLayout) technicianAllotment.getChildAt(listCount);
                            ListView workLayoutList = (ListView) linearLayout.getChildAt(1);

                            customerVoiceWorkListCustomAdapter = new CustomerVoiceWorkListCustomAdapter(context, 5, true);

                            workLayoutList.setAdapter(customerVoiceWorkListCustomAdapter);



                            UtilityClass.setListViewHeightBasedOnChildren(workLayoutList, "", "");
                        }

                    }
                    break;

                case DragEvent.ACTION_DRAG_LOCATION:  //This is used to scroll when dragged image is dragged to the bottom of screen


                    LinearLayout dropZoneView = (LinearLayout) v.getParent();

                    int topOfDropZone = dropZoneView.getTop();
                    int bottomOfDropZone = dropZoneView.getBottom();

                    int scrollY = recyclerView.getScrollY();
                    int scrollViewHeight = recyclerView.getMeasuredHeight();

                    Log.d("Log", "location: Scroll Y: " + scrollY + " Scroll Y+Height: " + (scrollY + scrollViewHeight));
                    Log.d("Log", " top: " + topOfDropZone + " bottom: " + bottomOfDropZone);

                    if (bottomOfDropZone > (scrollY + scrollViewHeight - 100)) {  //Manual scrolling down when image is dragged to bottom RV item
                        notifyDataSetChanged();
                        recyclerView.smoothScrollBy(0, 300);
                    }
                    if (topOfDropZone < (scrollY + 50))  //Manual scrolling up
                        recyclerView.smoothScrollBy(0, -50);

                    break;

                //the drag and drop operation has concluded.
                case DragEvent.ACTION_DRAG_ENDED:
                    if(v.getId() >= 100 && v.getId() < 150)
                    v.setBackground(normalShape);    //go back to normal shape

                default:
                    break;
            }
            return true;
        }
    }
@覆盖
公共无效onBindViewHolder(MyHolder,int位置){
Log.d(“Log”,“OnBindViewHolder”+位置);
holder.customerVoiceTitle.setText(hashMap.get(position));//设置标题文本-“客户语音[position+1]”
holder.customerVoiceTitle.setId(位置+100);//设置id以便在执行拖动操作时能够检测每个标题
holder.customerVoiceTitle.setOnDragListener(新的MyDragListener());
customerVoiceMainHeaderText.setId(50);//暂时忽略这一点,这也是问题的一部分。
customerVoiceMainHeaderText.setOnDragListener(新的MyDragListener());
holder.totalWorkLayoutListView.setId(位置+150);//ListView还用于执行拖动操作
holder.TotalWorklayOutList.setOnDragListener(新的MyDragListener());
UtilityClass.setListViewHeightBasedOnChildren(holder.TotalWorkLayOutList视图,“,”;//避免高度膨胀问题
/*如果(所有标志){
customerVoiceWorkListCustomAdapter=新的customerVoiceWorkListCustomAdapter(上下文,5,true);
}
如果(!allFlag),则为else{
customerVoiceWorkListCustomAdapter=新customerVoiceWorkListCustomAdapter(上下文,5,false);
}*/
holder.totalWorkLayoutListView.setAdapter(customerVoiceWorkListCustomAdapter);
}
类MyDragListener实现View.OnDragListener{
Drawable normalShape=context.getResources().getDrawable(R.Drawable.bg_fragment_header_和_border);
Drawable targetShape=context.getResources().getDrawable(R.Drawable.target_shape);
@凌驾
公共布尔onDrag(视图v,DrageEvent事件){
//处理每个预期事件
开关(event.getAction()){
//开始拖放操作的信号。
案例DrageEvent.ACTION\u DRAG\u已启动:
//无所事事
打破
//拖动点已进入视图的边界框
案例DrageEvent.ACTION\u DRAG\u输入:
如果(v.getId()>=100&&v.getId()<150)//仅用于标题文本
v、 setBackground(targetShape);//更改视图的形状
打破
//用户已将拖曳阴影移动到视图的边界框外
案例DrageEvent.ACTION\u DRAG\u退出:
如果(v.getId()>=100&&v.getId()<150)//仅用于标题文本
v、 setBackground(normalShape);//将视图的形状更改回法线
打破
//已释放拖曳阴影,拖曳点位于视图的边界框内
案例DrageEvent.ACTION_DROP:
Log.d(“Log”,“v.getId());
//如果视图是底部线性视图,则接受拖动项
如果(v.getId()>=100&&v.getId()<150){//仅用于标题文本。如果拖放图像,则列表中会发生一些更改。现在不导入
TextView workListHeaderText=(TextView)v;
LinearLayout containerLayout=(LinearLayout)workListHeaderText.getParent();
ListView workLayoutList=(ListView)containerLayout.getChildAt(1);
customerVoiceWorkListCustomAdapter=新的customerVoiceWorkListCustomAdapter(上下文,5,true);
workLayoutList.setAdapter(customerVoiceWorkListCustomAdapter);
}else if(v.getId()==50){
allFlag=true;
TextView workListRootHeaderText=(TextView)v;
LinearLayout布局=(LinearLayout)workListRootHeaderText.getParent();
RecyclerView Technician分配=(RecyclerView)布局。getChildAt(1);
int childCount=technicianAllocation.getChildCount();
对于(int-listCount=0;listCount