0

下面的类在数组中使用。

package com.example.ShivitoMGO;

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

主要活动

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;

在这个应用程序中,回收器视图创建“房间”,如果选择了房间,则 textview 和其他 2 个值被放入 RoomTable。这些被存储并在服务中使用以检查其他值是否发生变化。除非我使用 swip-to-refresh 女巫再次运行回收器视图,否则一切都按预期工作。如果我不刷新并且我在回收站视图中选择了相同的项目,它将从CountCheck中删除. 但是,如果我运行刷新并选择我之前选择的相同回收器视图项目,它将添加它而不是删除它。这对我来说没有任何意义,因为我使用 for 循环来检查 CountCheck.get(i).RoomName aka textview,如果名称相同,那么我的 if 语句将删除而不是添加。有没有可能我最终得到 2 个 CountCheck 对象??????同名???请我对这个没有想法。谢谢。

4

1 回答 1

0

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

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

对此

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

这解决了这个问题。如果您正在阅读本文,请告诉我其中的区别。

于 2019-12-26T21:09:00.857 回答