Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用andoird中的java获取firebase中子级的列表大小?_Java_Android_Firebase_Firebase Realtime Database - Fatal编程技术网

如何使用andoird中的java获取firebase中子级的列表大小?

如何使用andoird中的java获取firebase中子级的列表大小?,java,android,firebase,firebase-realtime-database,Java,Android,Firebase,Firebase Realtime Database,我有一些按钮,如果从firebase上的子“pin”列表大小,则按钮标题将更改为“插入您的pin”=0 在这里,添加新的pin码,但如何检测size!=0 我的代码: reference.child("pin").child(userID).addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot

我有一些按钮,如果
从firebase上的子“pin”列表大小,则按钮标题将更改为“插入您的pin”=0

在这里,添加新的pin码,但如何检测
size!=0

我的代码:

reference.child("pin").child(userID).addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                for (DataSnapshot snapshot : dataSnapshot.getChildren()){
                    Pin pinLogin = snapshot.getValue(Pin.class);
                    pinLogin.setKey(pinLogin.getKey());

                    pin.add(pinLogin);
                }
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });
          if(pin.size == 0){
                        reference.child("pin").child(userID).push()
                                .setValue(new Pin(pinEditText))
                                .addOnSuccessListener(new OnSuccessListener<Void>() {
                                    @Override
                                    public void onSuccess(Void aVoid) {
                                        dialog.setTitleText("Success");
                                        dialog.setContentText("Pin Has Been Added!");
                                        dialog.show();
                                    }
                                })
                                .addOnFailureListener(new OnFailureListener() {
                                    @Override
                                    public void onFailure(@NonNull Exception e) {
                                        dialogError.setTitleText("Error");
                                        dialogError.setContentText(e.getMessage());
                                    }
                                });
                  }else{
                     button.setText("Insert Your Pin");

我的按钮逻辑:

reference.child("pin").child(userID).addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                for (DataSnapshot snapshot : dataSnapshot.getChildren()){
                    Pin pinLogin = snapshot.getValue(Pin.class);
                    pinLogin.setKey(pinLogin.getKey());

                    pin.add(pinLogin);
                }
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });
          if(pin.size == 0){
                        reference.child("pin").child(userID).push()
                                .setValue(new Pin(pinEditText))
                                .addOnSuccessListener(new OnSuccessListener<Void>() {
                                    @Override
                                    public void onSuccess(Void aVoid) {
                                        dialog.setTitleText("Success");
                                        dialog.setContentText("Pin Has Been Added!");
                                        dialog.show();
                                    }
                                })
                                .addOnFailureListener(new OnFailureListener() {
                                    @Override
                                    public void onFailure(@NonNull Exception e) {
                                        dialogError.setTitleText("Error");
                                        dialogError.setContentText(e.getMessage());
                                    }
                                });
                  }else{
                     button.setText("Insert Your Pin");

if(pin.size==0){
reference.child(“pin”).child(userID.push())
.setValue(新引脚(文本))
.addOnSuccessListener(新的OnSuccessListener(){
@凌驾
成功时公开作废(作废避免){
dialog.setTitleText(“成功”);
setContentText(“已添加Pin!”);
dialog.show();
}
})
.addOnFailureListener(新的OnFailureListener(){
@凌驾
public void onFailure(@NonNull异常e){
dialogError.setTitleText(“错误”);
dialogError.setContentText(例如getMessage());
}
});
}否则{
button.setText(“插入Pin”);

如果您想使用
dataSnapshot.getChildrenCount()获取尺寸,我们将不胜感激