我有一个片段,其中将显示使用我的应用程序的所有用户。当用户点击其中一个用户时,他将被引导到聊天课程,在那里他将能够聊天。但问题是,无论用户点击哪个用户,他都会被引导到同一个聊天室。例如,如果我发短信" stackoverflow"给姓名" X"和开放的人名为" Y" " stackoverflow也将在那里
我的listview itemclick听众
usersList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
UserDetails.chatWith = al.get(position);
Intent intent = new Intent(getActivity(), Chat.class);
intent.putExtra("name",al.get(position));
intent.putExtra("user_id",userid);
startActivity(intent);
}
});
return rootView;
SendMessage方法
private void sendMessage() {
String messageText = messageArea.getText().toString();
if (TextUtils.isEmpty(messageText)){
Toast.makeText(getApplicationContext(),"Can't Send Blank Message",Toast.LENGTH_SHORT).show();
}
else {
String message_sender_ref = "Messages/" + MessageSenderId + "/" + MessageRecieverId;
String message_reciver_ref = "Messages/" + MessageRecieverId + "/" + MessageSenderId;
DatabaseReference user_message_key = rootRef.child("Messages").child(MessageSenderId)
.child(MessageRecieverId).push();
String message_push_id = user_message_key.getKey();
Map messageTextBody = new HashMap<>();
messageTextBody.put("message",messageText);
messageTextBody.put("seen",false);
messageTextBody.put("type","text");
messageTextBody.put("time", ServerValue.TIMESTAMP);
messageTextBody.put("from", MessageSenderId);
Map messageBodyDetails = new HashMap();
messageBodyDetails.put(message_sender_ref + "/" + message_push_id,messageTextBody);
messageBodyDetails.put(message_reciver_ref + "/" + message_push_id,messageTextBody);
rootRef.updateChildren(messageBodyDetails, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
if (databaseError != null){
Log.d("Chat_Log", databaseError.getMessage().toString());
}
messageArea.setText("");
}
});
}
}
我哪里出错了?我有点想在项目点击监听器上,因为当我点击任何项目时,它指向同一个房间。我该如何解决这个问题?请帮忙