【问题标题】:want to retrieve the only Rupees value from firebase database?想从 firebase 数据库中检索唯一的卢比值吗?
【发布时间】:2019-04-19 15:00:34
【问题描述】:

你可能认为这篇文章是重复的,但相信我,我已经尝试了所有这些,但这不会让我接近解决方案。

我是初学者,目前处于学习阶段。

我只想在 textview 中检索来自 standard 1stSchool no 109Gat No 14rupees

这是数据库树

这是我的代码。

java

    public class Collection extends AppCompatActivity {

    TextView ttl;
    Button btnshw;
    DatabaseReference d2ref;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_collection);ttl = (TextView) findViewById(R.id.texirs);
        btnshw = (Button) findViewById(R.id.bshow);

        btnshw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                d2ref = FirebaseDatabase.getInstance().getReference().child("2018-19").child("Gat No 14")
                        .child("School no 109").child("Standard 1st");
                d2ref.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                        for (DataSnapshot dsnap : dataSnapshot.getChildren()) {
                            Map<String, String> map = (Map)dsnap.getValue();
                            if(map != null) {
                                String gat = dataSnapshot.child("Rupees").getValue().toString();
                                ttl.setText(gat);
                                Log.d("Tag",gat);
                            }
                        }
                    }

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

                    }
                });
            }
        });
    }
}

请帮忙!!

【问题讨论】:

    标签: android firebase-realtime-database textview


    【解决方案1】:

    试试这个:-

     d2ref = FirebaseDatabase.getInstance().getReference().child("2018-19").child("Gat No 14")
                        .child("School no 109").child("Standard 1st");
                d2ref.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
    
    
                          String gat = dataSnapshot.child("Rupees").getValue().toString();
                         // and set tha gat in your textView
                    }
    
                    @Override
                    public void onCancelled(@NonNull DatabaseError databaseError) {
    
                    }
                });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 1970-01-01
    相关资源
    最近更新 更多