0
dbRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
for (final DataSnapshot ds : dataSnapshot.getChildren()){
arr.add(ds.child("name").getValue().toString()+"--"+ds.child("id").getValue().toString());
//ds.child("id").getValue().toString() this is how i get id from database
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplication(),"id :"+ds.getKey(),Toast.LENGTH_SHORT).show();
}
});
}
lv.setAdapter(arrayAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
這就是我如何從Firebase獲取數據並將其發佈到列表視圖中。 onItemClick我想在烤麪包中顯示用戶的ID(來自數據庫)。從Firebase中檢索數據並在列表視圖中填充它們
是的但我想隱藏在列表視圖中的id值 –