public class UserId {
public String user_id;
public <T extends UserId> T withId(@NonNull final String id){
this.user_id=id;
return(T) this;
}
}
@Override
public void onStart() {
super.onStart();
firebaseFirestore.collection("Users").addSnapshotListener(new
EventListener<QuerySnapshot>() {
@Override
public void onEvent(QuerySnapshot documentSnapshots,
FirebaseFirestoreException e) {
usersList.clear();
for(DocumentChange ds:documentSnapshots.getDocumentChanges()){
if(ds.getType()==DocumentChange.Type.ADDED){
String user_id=ds.getDocument().getId();
Users
users=ds.getDocument().toObject(Users.class).withId(user_id);
usersList.add(users);
userAdapter.notifyDataSetChanged();
}
}
}
});
}
在消防局中,我使用这些行
(
String user_id=ds.getDocument().getId();
Users users=ds.getDocument().toObject(Users.class).withId(user_id);
)
但是在实时Firebase中我可以使用什么?
我在消防局使用此方法获取用户ID。现在,我在实时数据库上工作,我想在这里检索用户ID。请帮我可以吗?
@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
posi=position;
ChatUsers listItems = listitem.get(position);
viewHolder.name.setText(listItems.getName());
viewHolder.status.setText(listItems.getStatus());
String thumb_img=listItems.getThumb_img();
RequestOptions requestOptions=new RequestOptions();
requestOptions.placeholder(R.drawable.defaultimage);
Glide.with(context).setDefaultRequestOptions(requestOptions)
.load(thumb_img).into(viewHolder.img);
viewHolder.v1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context,"jj",Toast.LENGTH_LONG).show();
Intend in=new Intent(this,Setting.class);
// here I want to send user id
}
});
Picasso.with(context).load(thumb_img).
placeholder(R.drawable.bus2).into(viewHolder.img);
}
答案 0 :(得分:0)
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d(TAG, document.getId() + " => " + document.getData());
}