首页 > 解决方案 > 存储到firebase数据库后如何禁用其他人的复选框值?

问题描述

在这里,我正在研究一个基于 android 中的停车场的项目。在这种情况下,用户首先选择综合体,然后选择停车位,然后预订这个地方,这是我的场景。我的问题是,如果用户在特定综合体中预订了一个位置,那么如何为其他用户禁用该特定位置。

我在复选框中给出了位置,我不想使用单选按钮,因为一个用户可以为他的朋友预订一个地方,所以一个用户可以预订两个地方。

我刚刚在 firebase 数据库上添加了值和其他详细信息,我在数据库中添加值的代码是。

这是我在数据库中上传值的代码:

           checkupdate = FirebaseDatabase.getInstance().getReference().child("Users").child(coID).child(slotID).child(place).child(phone).child("place");
                        Avilsize = FirebaseDatabase.getInstance().getReference().child("Users").child(coID).child(slotID).child(place).child(phone);

                        HashMap<String, Object> avilsizetMap = new HashMap<>();

                        if (place.equals("place1"))
                        {
                            int a = check + 1;
                            bookplace = (String) "place1";

                            check = a;
                            String b = "value" + a;
                            HashMap<String, Object> checkmap = new HashMap<>();
                            checkmap.put("Value", "place1");
                            checkupdate.child(b).updateChildren(checkmap);

                        }
                        if (place.equals("place2")) {
                            int a = check + 1;

                            bookplace = bookplace + "/" + (String) "place2";

                            check = a;
                            String b = "value" + a;
                            HashMap<String, Object> checkmap = new HashMap<>();
                            checkmap.put("Value", "place2");
                            checkupdate.child(b).updateChildren(checkmap);

                        }
                        if (place.equals("place3")) {
                            int a = check + 1;
                            bookplace = bookplace + "/" + (String) "place3";

                            check = a;
                            String b = "value" + a;
                            HashMap<String, Object> checkmap = new HashMap<>();
                            checkmap.put("Value", "place3");
                            checkupdate.child(b).updateChildren(checkmap);

                        }
                        if (place.equals("place4")) {
                            int a = check + 1;
                            bookplace = bookplace + "/" + (String) "place4";

                            check = a;
                            String b = "value" + a;
                            HashMap<String, Object> checkmap = new HashMap<>();
                            checkmap.put("Value", "place4");
                            checkupdate.child(b).updateChildren(checkmap);

                        }
                        if (place.equals("place5")) {
                            int a = check + 1;
                            bookplace = bookplace + "/" + (String) "place5";

                            check = a;
                            String b = "value" + a;
                            HashMap<String, Object> checkmap = new HashMap<>();
                            checkmap.put("Value", "place5");
                            checkupdate.child(b).updateChildren(checkmap);

                        }
                        if (place.equals("place6")) {
                            int a = check + 1;
                            bookplace = bookplace + "/" + (String) "place6";

                            check = a;
                            String b = "value" + a;
                            HashMap<String, Object> checkmap = new HashMap<>();
                            checkmap.put("Value", "place6");
                            checkupdate.child(b).updateChildren(checkmap);
                        }
                        avilsizetMap.put("book_place", bookplace);
                        Avilsize.updateChildren(avilsizetMap);

我的数据库结构 这是我的数据库结构

我尝试了一组代码来检索值,但它不起作用,代码在这里

                       final List<String >  areas = new ArrayList<>();

                        for (DataSnapshot areaSnapshot : dataSnapshot.getChildren())
                        {
                            String areaName = areaSnapshot.child("Value").getValue(String.class);
                            areas.add(areaName);
                        }
                        for (String area : areas)
                        {
                            if(area.equals("place1"))
                            {
                                Place1.setChecked(true);
                            }
                            if(area.equals("place2")){
                                Place2.setChecked(true);
                            }
                            if(area.equals("Place3")){
                                Place3.setChecked(true);
                            }
                            if(area.equals("Place4")){
                                Place4.setChecked(true);
                            }
                            if(area.equals("Place5")){
                                Place5.setChecked(true);
                            }
                            if(area.equals("Place6")){
                                Place6.setChecked(true);
                            }
                        }

这是我在 xml 中的布局

        <LinearLayout
            android:id="@+id/ll1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="#FFF"
            android:gravity="center"
            android:layout_marginRight="20dp"
            android:layout_marginLeft="20dp"
            android:orientation="horizontal"
            android:padding="20dp">

              <TableLayout
                 android:padding="3dp"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:stretchColumns="3">
                    <TableRow>
                       <CheckBox
                           android:id="@+id/pl1"
                           android:layout_width="40dp"
                           android:layout_height="40dp"
                           android:tag="place1"
                           android:button="@drawable/checkbox_bg"
                           />
                       <CheckBox
                           android:id="@+id/pl2"
                           android:layout_width="40dp"
                           android:tag="place2"
                           android:layout_height="40dp"
                           android:button="@drawable/checkbox_bg"
                           />
                       <CheckBox
                           android:id="@+id/pl3"
                           android:layout_width="40dp"
                           android:tag="place3"
                           android:layout_height="40dp"
                           android:button="@drawable/checkbox_bg"
                           />
                    </TableRow>
              </TableLayout>

              <TableLayout
                 android:id="@+id/table2"
                 android:layout_marginLeft="70dp"
                 android:layout_width="wrap_content"
                 android:padding="3dp"
                 android:layout_height="wrap_content"
                 android:stretchColumns="3">
                    <TableRow>
                        <CheckBox
                            android:id="@+id/pl4"
                            android:layout_width="40dp"
                            android:layout_height="40dp"
                            android:tag="place4"
                            android:button="@drawable/checkbox_bg"
                            />
                        <CheckBox
                            android:id="@+id/pl5"
                            android:layout_width="40dp"
                            android:layout_height="40dp"
                            android:tag="place5"
                            android:button="@drawable/checkbox_bg"
                            />
                       <CheckBox
                           android:id="@+id/pl6"
                           android:layout_width="40dp"
                           android:layout_height="40dp"
                           android:tag="place6"
                           android:button="@drawable/checkbox_bg"
                           />
                     </TableRow>
               </TableLayout>

          </LinearLayout>

         <Button
                android:id="@+id/next"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:textColor="#FFF"
                android:layout_marginBottom="10dp"
                android:textSize="30sp"
                android:fontFamily="cursive"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                android:padding="5dp"
                android:background="@drawable/btn_bg"
                android:text="Book" />

我希望有人给我一个解决方案谢谢...

标签: androidfirebaseloopsandroid-layoutfirebase-realtime-database

解决方案


推荐阅读