我在数据库中有数据: database in firebase
我想要阅读所有孩子(Belgia,Czechy,Polska ......)并在文本字段中显示它,但是点击按钮后(我不更改数据库中的数据)。 该按钮分配了以下功能:
augroup my_changelist
au!
au BufWinLeave * call s:get_change_position()
au BufWinEnter * call s:restore_change_position()
augroup END
fu! s:get_change_position() abort
let changelist = split(execute('changes'), "\n")
let b:my_change_position = {
\ 'idx': index(changelist, matchstr(changelist, '^>.*')),
\ 'view': winsaveview(),
\ }
if b:my_change_position.idx == -1
let b:my_change_position.idx = 100
endif
endfu
fu! s:restore_change_position() abort
if exists('b:my_change_position.idx') && exists('b:my_change_position.view')
sil! exe 'norm! 99g;'. (b:my_change_position.idx - 1) .'g,'
call winrestview(b:my_change_position.view)
endif
endfu
Befrore我在代码中写道:
public void f_btn_zaczytaj_dane(View view) {
myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
TextView txt_opis_panstwa = (TextView) findViewById(R.id.txt_opis_panstwa);
txt_opis_panstwa.setText(value);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
不幸的是,当我按下按钮时没有任何反应。
我将非常感谢你的帮助 此致,Marcin
答案 0 :(得分:0)
你必须遍历你的孩子
public void f_btn_zaczytaj_dane(View view) {
myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
TextView txt_opis_panstwa = (TextView) findViewById(R.id.txt_opis_panstwa);
for (DataSnapshot country : dataSnapshot.getChildren()) {
txt_opis_panstwa.append(country.getKey());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
答案 1 :(得分:0)
请使用此代码:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference krajRef = rootRef.child("flagiistolice").child("kraj");
public void f_btn_zaczytaj_dane(View view) {
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
TextView txt_opis_panstwa = (TextView) findViewById(R.id.txt_opis_panstwa);
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String country = ds.getkey();
txt_opis_panstwa.append(country);
Log.d("TAG", country);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
krajRef.addListenerForSingleValueEvent(eventListener);
}