简体   繁体   English

如何从 firebase 数据库中检索特定用户 ID 的数据

[英]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.

相关问题 如何从 firebase 中检索这些数据? - How to retrive this data from firebase? 如何使用JDBC从SQL数据库中检索特定数据? - How to retrive specific data from a SQL database with JDBC? 从Firebase数据库中检索特定用户的数据 - Retrieve data of a specific user from a Firebase database 如何从 Firebase 实时数据库中检索具有 UID 的特定用户的特定数据 - How to retrieve specific data of a specific user with UID from a Firebase realtime database 从 Firebase 实时数据库中为特定用户读取数据 - Reading data from Firebase Realtime Database for a specific user Android:从Firebase数据库检索特定用户的数据 - Android: Retrieve data of a specific user from a Firebase database 如何在Firebase数据库中显示特定当前登录用户的数据? - How to display data of specific current logged in user in Firebase Database? 如何通过 Id 获取用户并从 firebase auth 数据库中删除它 - How to get a user by Id and delete it after from firebase auth database 如何从数据库中检索数据并在具有多个复选框的列表视图中显示? - How to Retrive Data From The Database and Display in listview with multiple checkboxes? 如何从数据库中检索数据并在netbeans中的JLabel上显示 - how to retrive the data from database and show on JLabel in netbeans
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM