Basically, I read messages from firebase database one by one in a loop after which, I want to add each message to the linear layout.
I have a Linear Layout XML file like this called my_linear_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layout2"
android:layout_marginTop="20dp"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="6"
android:background="@drawable/rounded_corner"
android:padding="16dp"
android:text="MESSAGE GOES HERE. IT CAN BE A LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG MESSAGE"
android:textColor="#000" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="0dp"
android:layout_weight="3"
android:src="@drawable/senduser" />
</LinearLayout>
Now, want to inflate this layout in my Activity's Relative Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
tools:context=".BuyerChat">
<ScrollView
android:layout_width="match_parent"
android:layout_weight="20"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
</RelativeLayout>
</ScrollView>
<include
layout="@layout/type_message_area"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="bottom" />
</LinearLayout>
I can not just add the code here because I want to have n number of linear layouts, depending on how many messages I have. Basically, I read messages from firebase database after which, I want to add each message to the linear layout.
So, I want a code snippet that will allow me to add a linear layout everytime I call it and place a new message in linear layout every time.
I have been at this for quite some time, please help.