Java 是否根据当前用户uid检查数据库项的子值?

Java 是否根据当前用户uid检查数据库项的子值?,java,android,firebase,firebase-realtime-database,Java,Android,Firebase,Firebase Realtime Database,有没有办法根据当前用户的uid检查数据库中的子值 我基本上希望显示一条错误消息/toast,说明用户无法删除其他用户的账单 我的数据库结构如下所示(uid是我要与当前用户的uid进行比较的字段): 我目前有一个if-else语句,用于检查是否输入了某些详细信息: if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(payer) && !TextUtils.isEmpty(amount) && (!

有没有办法根据当前用户的uid检查数据库中的子值

我基本上希望显示一条错误消息/toast,说明用户无法删除其他用户的账单

我的数据库结构如下所示(uid是我要与当前用户的uid进行比较的字段):

我目前有一个if-else语句,用于检查是否输入了某些详细信息:

if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(payer) && !TextUtils.isEmpty(amount) && (!TextUtils.isEmpty(date))) {
    updateBill(billId, title, payer, amount, date, details, uid);
                    alertDialog.dismiss();

                }


                else {
                    Toast.makeText(MainActivity.this, "Please enter the Title, Payer, Amount and Date", Toast.LENGTH_SHORT).show();

                }

            }
编辑:删除代码:

private boolean deleteBill(String id) {
        //Getting the specified Bill reference by looking at the ID
        DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Bills").child(id);
        //Removing the ID
        databaseReference.removeValue();
        Toast.makeText(getApplicationContext(), "Bill Deleted Successfully", Toast.LENGTH_LONG).show();
        return true;
    }

这将帮助您解决您的问题

DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference().child("Bills").child(id)
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if(FirebaseAuth.getInstance().getCurrentUser().getUid().equals(dataSnapshot.child("uid").getValue(String.class))){
                databaseReference.removeValue();
                Toast.makeText(getApplicationContext(), "Bill Deleted Successfully", Toast.LENGTH_LONG).show();
            }else{
                Toast.makeText(getApplicationContext(), "You're not authorized User to Delete Bill", Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });;

请发布删除账单代码,以便我们能够为您提供正确答案添加删除方法请仅使用
android studio
标签来回答有关android studio IDE本身的问题。有关Android编程的一般问题,请使用
Android
标记。