我有这个数组 class 在重新 运行 我的 recyclerview 后没有删除项目

I have this array class that is not removing items after re-running my recyclerview

下面的class用在数组中

package com.example.ShivitoMGO;

public class RoomTable {
    public String RoomName,UpDown,minmaxint;
}

主要Activity

static ArrayList <RoomTable> CountCheck = new ArrayList<>();

    public void playerup(View vvv){

        st_spinner = v1.findViewById(R.id.spinner);
        st_reportLayout = v1.findViewById(R.id.reportlayout);
        st_Leanervidimg = v1.findViewById(R.id.Linearvidcopy);
        TextView roomname = v1.findViewById(R.id.action_Players1);
        RoomTable roomtb = new RoomTable();
        if (CountCheck.size() == 0){
            //playerupdown = "up";

            Toast.makeText(this, "Will notify when " + mRooms.get(position1) + " players increase  #" + mRoomSize.get(position1), Toast.LENGTH_LONG).show();
            String[] minmaxval = mRoomSize.get(position1).split("/");
            CountCheckint = Integer.parseInt(minmaxval[0].trim());
            //CountCheck = (String) mRooms.get(position1);

            roomtb.RoomName = (String) mRooms.get(position1);
            roomtb.minmaxint = minmaxval[0].trim();
            roomtb.UpDown = "up";
            Log.d("added: ", "it was added");
            CountCheck.add(roomtb);
            Log.d("RoomTableadd: ",roomtb.RoomName+ " " + roomtb.minmaxint +" " +roomtb.UpDown);
            st_reportLayout.setVisibility(View.GONE);
            Log.d("Longclickhere: ", mRoomSize.get(position1));
            Log.d("RoomNameCount ", String.valueOf(CountCheck.get(0).RoomName));
        }else {
            int exist1 = 0;
            int poss;
            for (int i = 0; i < CountCheck.size(); i++) {
                if (roomname.getText() == CountCheck.get(i).RoomName) {
                    Log.d("RoomNametxt: " , CountCheck.get(i).RoomName);
                    Log.d("RoomNametxt: ", (String) roomname.getText());
                    Toast.makeText(this, "Notification " + CountCheck.get(i).RoomName + " OFF!", Toast.LENGTH_LONG).show();
                    Log.d("Removed item: ", String.valueOf(CountCheck.size()));
                    CountCheck.remove(i);
                    Log.d("Removed item: ", String.valueOf(CountCheck.size()));
                    st_reportLayout.setVisibility(View.GONE);
                    exist1 = 1;
                    poss = i;
                } else {
                    exist1 = 0;
                }
            }
            if (exist1 == 0) {
                Toast.makeText(this, "Will notify when " + mRooms.get(position1) + " players increase  #" + mRoomSize.get(position1), Toast.LENGTH_LONG).show();
                String[] minmaxval = mRoomSize.get(position1).split("/");
                CountCheckint = Integer.parseInt(minmaxval[0].trim());
                //CountCheck = (String) mRooms.get(position1);

                roomtb.RoomName = (String) mRooms.get(position1);
                roomtb.minmaxint = minmaxval[0].trim();
                roomtb.UpDown = "up";
                Log.d("added: ", "it was added");
                CountCheck.add(roomtb);
                Log.d("RoomTableadd: ", roomtb.RoomName + " " + roomtb.minmaxint + " " + roomtb.UpDown);
                st_reportLayout.setVisibility(View.GONE);
            }





            Log.d("CountSize: ", String.valueOf(CountCheck.size()));
            for (int xb = 0;xb<CountCheck.size();xb++) {
                try {
                    Log.d("RoomNameCount ", String.valueOf(CountCheck.get(xb).RoomName));


                } catch (Exception e) {
                    Log.d("Out of range ", String.valueOf(e));
                }
            }

        }
    }

回收站视图

            @Override
            public boolean onLongClick(View v) {
                // Launch your web intent
                if (CountCheck.size() != 0){
                    Log.d("Longclickhere: ",mRoomSize.get(position));
                    Toast.makeText(mContext, mRoomSize.get(position), Toast.LENGTH_SHORT).show();
                    Toast.makeText(mContext, "Will notify when "+mRooms.get(position)+" players decrease", Toast.LENGTH_SHORT).show();
                    String[] minmaxval = mRoomSize.get(position).split("/");
                    MainActivity.CountCheckint = Integer.parseInt(minmaxval[0].trim());


                } else{
                    //MainActivity.CountCheck = "";
                    Toast.makeText(mContext, "Player Decrease notification OFF", Toast.LENGTH_SHORT).show();
                }
                return true;

在此应用程序中,回收器视图会创建 "rooms",如果房间已 selected,则会将文本视图和其他 2 个值放入 RoomTable。这些被存储并在服务中使用,以检查其他以太值是否发生变化。一切都按预期工作,除非我再次使用滑动刷新 运行s 回收站视图。如果我不刷新并且我 select 回收站视图中的相同项目,它将从 CountCheck 中删除它。但是,如果我 运行 刷新和 select 我之前 select 编辑的相同回收站视图项目,它将添加它而不是删除它。这对我来说没有意义,因为我使用 for 循环来检查 CountCheck.get(i).RoomName aka textview,如果名称相同,那么我的 if 语句将删除而不是添加。有没有可能我最终得到 2 个 CountCheck 对象?????同名????拜托,我对此一无所知。谢谢。

我不记得为什么了。也许有人可以解释,但我更改了这一行

if (roomname.getText() == CountCheck.get(i).RoomName)

对此

if (roomname.getText().equals(CountCheck.get(i).RoomName));

这解决了问题。如果您正在阅读本文,请告诉我不同​​之处。