LoadUserInfo Method
LoadUserInfo方法
public void loadUserInformation() {
final String uid = mAuth.getCurrentUser().getUid();
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference().child("Users");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot postSnapshot: dataSnapshot.getChildren()){
// String name=postSnapshot.child("Name").getValue().toString();;
// Name.setText(name);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getApplicationContext(),"Error Loading Messages",Toast.LENGTH_LONG).show();
}
};
rootRef.addListenerForSingleValueEvent(eventListener);
}
I know how to fetch a static data like a data which is defined by me. But i want to retrive messages and display in listview. the problem is i use push method and every message creates a unique id and inside it contains message. how to i ignore the unique id and just fetch the message and display in listview? can some provide the code for adapter cuz im still a beginner... Datatbase - http://ibb.co/fcRrxG
我知道如何获取静态数据,就像我定义的数据一样。但我想要检索消息并在listview中显示。问题是我使用push方法,每条消息都创建一个唯一的id,里面包含消息。如何忽略唯一ID并只获取消息并在listview中显示?有些人可以提供适配器的代码,因为我还是初学者...... Datatbase - http://ibb.co/fcRrxG
1 个解决方案
#1
0
Try to make one single node of chat between two users in messages node in your database. Let say, make a node with your id and with your friend id and in that node add chat messages in HashMap. And, when retrieving it get that HashMap of your node.
尝试在数据库的消息节点中的两个用户之间建立一个单一的聊天节点。假设,使用您的id和您的朋友ID创建一个节点,并在该节点中添加HashMap中的聊天消息。并且,在检索它时,获取节点的HashMap。
#1
0
Try to make one single node of chat between two users in messages node in your database. Let say, make a node with your id and with your friend id and in that node add chat messages in HashMap. And, when retrieving it get that HashMap of your node.
尝试在数据库的消息节点中的两个用户之间建立一个单一的聊天节点。假设,使用您的id和您的朋友ID创建一个节点,并在该节点中添加HashMap中的聊天消息。并且,在检索它时,获取节点的HashMap。