[英]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 数据库结构如下:
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.