[英]How to retrive data to specific user id from firebase database
I have an android applucation.我有一个 android 应用程序。 I want to create a payment transaction history in this app.我想在这个应用程序中创建一个支付交易历史。 I have create a payment transaction activity and try to retrieve transaction history in a recyclerview.我创建了一个支付交易活动,并尝试在回收站视图中检索交易历史记录。 Its working now.它现在工作。
But the issue is the recycler view show the transaction history of all users.但问题是回收站视图显示所有用户的交易历史。 I want to show the transaction history in to current user.我想向当前用户显示交易历史。 That means when will I open my transaction history activity I want to see only my transaction history.这意味着我什么时候会打开我的交易历史活动,我只想查看我的交易历史。 Now I can see all users transaction history.现在我可以看到所有用户的交易历史。 How I get only my transaction history in my profile.我如何在我的个人资料中仅获取我的交易历史记录。 Sorry for my bad english.对不起,我的英语不好。
This is my code这是我的代码
MCC= FirebaseDatabase.getInstance().getReference().child("PAYTMWITHDRAWAL");
recyclerView = (RecyclerView) findViewById(R.id.aswam_recyclerView);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(new GridLayoutManager(this, 1));
LoadData(categoryId);
}
private void LoadData(String categoryId) {
options = new FirebaseRecyclerOptions.Builder<PayoutHistoryModel>().setQuery(MCC,PayoutHistoryModel.class).build();
adapter = new FirebaseRecyclerAdapter<PayoutHistoryModel, PayoutHistoryViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull PayoutHistoryViewHolder payoutHistoryViewHolder, int i, @NonNull PayoutHistoryModel trollModel) {
payoutHistoryViewHolder.thrillername.setText(trollModel.getPayoutStatus());
Picasso.get().load(trollModel.getImage())
.into(payoutHistoryViewHolder.thrillersimage);
}
@NonNull
@Override
public PayoutHistoryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.payout_histoy_layout, parent, false);
return new PayoutHistoryViewHolder(v);
}
};
adapter.startListening();
recyclerView.setAdapter(adapter);
If you have the UID
of the user in each transaction, you can use a query to order/filter the data.如果您在每个事务中都有用户的UID
,则可以使用查询来排序/过滤数据。
For example, if each transaction has a ownerUID
property you could do something like this:例如,如果每个事务都有一个ownerUID
属性,您可以执行以下操作:
private void LoadData(String categoryId) {
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
Query query = MCC.orderByChild("ownerUID").equalTo(uid); // 👈
options = new FirebaseRecyclerOptions.Builder<PayoutHistoryModel>()
.setQuery(query,PayoutHistoryModel.class).build();
// 👆
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.