I am following a tuturiol on youtube to create a chat app. The problem i am facing is that i do not seem to get the chats to be displayed the way whatsapp does, like the sender's should be at the right and the user's at the right. I tried a couple of methods using if else statements seem to align to one side. Here are my codes. And it is not like other questions as i have 2 different xmls and im trying to use java
chat_item_left.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.github.library.bubbleview.BubbleTextView
android:layout_alignParentStart="true"
android:layout_marginTop="5dp"
android:layout_below="@id/messageUser"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="#FFF"
android:textSize="18sp"
android:id="@+id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
app:arrowWidth="8dp"
app:angle="8dp"
app:arrowHeight="10dp"
app:arrowPosition="14dp"
app:arrowLocation="left"
app:bubbleColor="#333639"
app:arrowCenter="true"
android:text="hie"
android:layout_alignParentLeft="true" />
chat_item_right.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.github.library.bubbleview.BubbleTextView
android:layout_alignParentEnd="true"
android:layout_marginTop="5dp"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="#FFF"
android:textSize="18sp"
android:id="@+id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
app:arrowWidth="8dp"
app:angle="8dp"
app:arrowHeight="10dp"
app:arrowPosition="14dp"
app:arrowLocation="right"
app:bubbleColor="@android:color/holo_blue_bright"
app:arrowCenter="true"
android:text="hie"
android:layout_alignParentRight="true" />
And here is what i have done with my code so far
private void displayChatMessage() {
ListView listOfMessage = (ListView) findViewById(R.id.listOfMessage);
Query query = FirebaseDatabase.getInstance().getReference().child("chats");
FirebaseListOptions<ChatMessage> options = new FirebaseListOptions.Builder<ChatMessage>()
.setLayout(R.layout.chat_item_left)
.setQuery(query, ChatMessage.class)
.build();
adapter = new FirebaseListAdapter<ChatMessage>(options) {
@Override
protected void populateView(View v, ChatMessage model, int position) {
// Bind the Chat to the view
// ...
//get references to views of list_item.xml
TextView messageText ,messageUser,messageTime;
messageText = (BubbleTextView) v.findViewById(R.id.messageText);
messageText.setText(model.getMessageText());
}
};
listOfMessage.setAdapter(adapter);
}
Where do i specify to put the right alignemnt?