简体   繁体   English

我已经使用了数据库引用,那么为什么我要将所有用户数据都放入 recyclerview 我只希望一个用户数据进入 recycler 视图?

[英]I have used Database Reference then why i am getting all user data into recyclerview i only want only one user data into recycler view?

Below is my current recyler view screenshot...i am getting staydetails all 8 nodes data its ok when i search single user but it also add into list of another user child node staydetails data that i dont want.以下是我当前的回收器视图屏幕截图...当我搜索单个用户时,我得到了所有 8 个节点的详细信息数据,但它也添加到了另一个我不想要的用户子节点的列表中。

My Firebase DataBase Structure is as per below:我的 Firebase 数据库结构如下:

我的 Firebase 数据库结构

I want only single user "staydetails".我只想要单个用户“staydetails”。 Instead of that in my recycler Adapter i am getting all user data.而不是在我的回收器适配器中,我正在获取所有用户数据。

When I am adding multiple user and their room stay details while searching for one user it gives me all user staydetails data into adapter.当我在搜索一个用户时添加多个用户及其房间住宿详细信息时,它会将所有用户住宿详细信息数据提供给适配器。 Here is my MainActivity recycler view with adapter and database refrence.这是我的 MainActivity 回收器视图,带有适配器和数据库参考。 Thank you in Advance先感谢您

    final String userformno = mobileorformnosearch.getText().toString().trim();
    globalmobileno = userformno;
    if (userformno.trim().length() == 10) {
        list.clear();
        PassDataRef = FirebaseDatabase.getInstance().getReference().child("Passanger");
        PassDataRef.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                for (DataSnapshot datas : dataSnapshot.getChildren()) {


                    if (dataSnapshot.hasChild(userformno)) {
                        // run some code

                        //MobileNoDataWise
                        UserDataRegistration user = dataSnapshot.child(userformno).getValue(UserDataRegistration.class);

                        YatriName.setText(user.getUsername());
                        YatriAge.setText(user.getAge());
                        YatriCity.setText(user.getCity());
                        Yatriphonenumber.setText(user.getMobileno());
                        YatriformNo.setText(user.getFormno());
                        YatriCoachNo.setText(user.getCoachno());
                        YatriSeatNo.setText(user.getSeatno());
                        YatriBearth.setText(user.getBearth());
                        YatriBusno22.setText(user.getBustwono());
                        YatriBusSeatNo22.setText(user.getBustwoseatno());
                        YatriBusno32.setText(user.getBusthreeno());
                        YatriBusSeatNo32.setText(user.getBusthreeseatno());
                        YatriPhotoUri.setText(user.getProfilephoto());
                        YatriGender.setText(user.getGender());
                        YatriMBusno.setText(user.getMbusno());
                        YatriMBusSeatno.setText(user.getMseatno());
                        // String url ="https://firebasestorage.googleapis.com/v0/b/uttammangal-ad8b8.appspot.com/o/profilepic%2F223.jpg?alt=media&token=703bcc8f-c2c3-4beb-bffc-40e52daa572d";// user.getProfilephoto();
                        String Url = user.getProfilephoto();
                        if (Url != null) {

                            Picasso
                                    .get()
                                    .load(Url)
                                    .resize(200, 200) // resizes the image to these dimensions (in pixel)
                                    .centerCrop()
                                    .into(YatriImageView);
                            // Glide.with(getApplicationContext()).load(Url).into(YatriImageView);
                        } else {

                            Toast.makeText(MainActivity.this, "NO Image Found!!", Toast.LENGTH_LONG).show();

                        }

                        RecycleDataRef = FirebaseDatabase.getInstance().getReference("Passanger");
                        list.clear();
                       Query  qry = RecycleDataRef.child(userformno).child("StayDetails");
                        qry.addListenerForSingleValueEvent(new ValueEventListener() {
                            @Override
                            public void onDataChange(@NonNull DataSnapshot dataSnapshot1) {
                                for (DataSnapshot dataSnapshot2 : dataSnapshot1.getChildren()) {
                                    //UserDataRegistration user = dataSnapshot.child(userformno).getValue(UserDataRegistration.class);

                                        UserDataRetrieve u = dataSnapshot2.getValue(UserDataRetrieve.class);
                                        //UserDataRetrieve u = dataSnapshot1.getValue(UserDataRetrieve.class);

                                        list.add(u);

                                }

                                adapter = new MyAdapter(MainActivity.this, list);

                                recyclerView.setAdapter(adapter);
                            }

                            @Override
                            public void onCancelled(@NonNull DatabaseError databaseError) {

                            }
                        });


                    } else {
                        Toast toast = Toast.makeText(MainActivity.this, "No Record Found!!!!!", Toast.LENGTH_SHORT);
                        toast.setGravity(Gravity.CENTER, 0, 0);
                        toast.show();
                        break;
                    }

                }//ForloopClosing
                return;
            } //Main DataSnapshot Profile Data closing


            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
                Toast.makeText(MainActivity.this, "Please Enter Valid MobileNo!!", Toast.LENGTH_LONG).show();

            }


        }); //addvaluelistner main profile Data Closing

        //} //Query node equals closing


    } else {
        Toast.makeText(MainActivity.this, "Please Enter 10 Digit MobileNo!!", Toast.LENGTH_LONG).show();

    }

} //OnClick Closing

Instead of loop through all users you can simply get the user data that you want through search like below:您可以简单地通过搜索获取所需的用户数据,而不是遍历所有用户,如下所示:

FirebaseDatabase.getInstance().getReference().child("Passanger").child(userformno).addListenerForSingleValueEvent(
        new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                UserDataRegistration user = dataSnapshot.getValue(UserDataRegistration.class);

                ...

                if(dataSnapshot.hasChild("StayDetails")) {
                    for (DataSnapshot dataSnapshot2 : dataSnapshot.child("StayDetails").getChildren()) {
                        UserDataRetrieve u = dataSnapshot2.getValue(UserDataRetrieve.class);
                        //UserDataRetrieve u = dataSnapshot1.getValue(UserDataRetrieve.class);
                        list.add(u);
                    }

                   ...

                }
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
                Toast toast = Toast.makeText(MainActivity.this, "No Record Found!!!!!", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            }
        }
);

Hope this will give you the exact data that you want.希望这将为您提供所需的确切数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想将数据库的所有行显示为列表视图。但是我只有一个 - I want to show all rows of database as list view.But I am having only one API 正在获取所有 JSON 数据,但我的应用程序在回收站视图中只显示一个,我该怎么办? - API is fetching all the JSON data but my app displays only one in recycler view what should i do? 我正在尝试使用回收站视图从 Firebase 数据库中检索数据,但出现错误 - i am trying to retrieve the data from fire base database using recycler view but i am getting errors in it Firebase 数据未显示在回收站视图中。 如何在 recyclerview 中显示来自 firebase 的用户特定数据? - Firebase data not displaying in Recycler view. How do I display user specific data from firebase in recyclerview? 我正在制作一个项目,用户 API 调用并获取数据并在回收站视图中显示 - I am making a project where User API call and fetch the data and display in recycler view 我面临在回收站视图中设置数据的问题我已经测试过数据来自 API - I am facing a problem which setting the data in recycler view I have tested that data is coming from the API 当从数据库中获取数据时,只获取一行的第一个索引,我想要每一行的所有数据 - When fetching data from database getting first index of a row only i want all data from each row 为什么在RecyclerView中加载更多数据时会出现重复项? - Why am I getting duplicated items on loading more data in RecyclerView? 当我有两个recyclerview数据源,但是只有一个数据源被更改时,如何在recyclerview中使用notifyDataSetChanged() - How to use notifyDataSetChanged() in recyclerview, when I have two data sources for the recyclerview, but only one data source has been changed 我想在 recyclerview 中显示我的所有数据 - i want show all of my data in a recyclerview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM