Android ListView with different layouts for each row

Take a look in the code below. First, we create custom layouts. In this case, four types. even.xml <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:background=”#ff500000″ android:layout_height=”match_parent”> <TextView android:id=”@+id/text” android:textColor=”@android:color/white” android:layout_width=”match_parent” android:layout_gravity=”center” android:textSize=”24sp” android:layout_height=”wrap_content” /> </LinearLayout> odd.xml <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:background=”#ff001f50″ android:gravity=”right” android:layout_height=”match_parent”> <TextView android:id=”@+id/text” android:textColor=”@android:color/white” android:layout_width=”wrap_content” android:layout_gravity=”center” android:textSize=”28sp” android:layout_height=”wrap_content” /> </LinearLayout> white.xml <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:background=”#ffffffff” android:gravity=”right” android:layout_height=”match_parent”> … Read more