Search code examples
androidandroid-listviewexpandablelistview

How to change the property of first content of List View in Android


I have created an expandable listView where I am showing text side by side more likely I wanna show a table of 2 columns there. For that, I have used the expandable list view and so far it looks like this(The image below). my expandable list view

But I want to change the color of the first line of this list. something like this(image below). what i want

As for code, I have used two text views in a horizontal Linear Layout and with a custom adapter I am showing the data in the view. here's the XML.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/itemText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ellipsize="end"
        android:maxLines="1"
        android:textSize="16sp"
        android:text="item"/>

    <TextView
        android:id="@+id/itemText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ellipsize="end"
        android:maxLines="1"
        android:textSize="16sp"
        android:text="Item2"/>

</LinearLayout>

Can anyone suggest what should I do to achieve this?


Solution

  • In your adapter if position = 0

    itemText.setBackgroundColor(int colour);
    

    Also you should use RecyclerView instead of ListView