crazyTechie
crazyTechie

Reputation: 2557

android list view - row color

I am trying to develop a simple android app. It has two text boxes for entering search criteria. A submit button to submit the page. In the next page (new intent) I show search results.

Now I want to search results in a listview. The xml code of the view looks like below.

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

 <ImageView
    android:id="@+id/image"
    android:layout_width="50px"
    android:layout_height="50px"
    android:layout_marginLeft="5px"
    android:layout_marginRight="20px"
    android:layout_marginTop="5px">
</ImageView>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" 
android:orientation="vertical">

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@+id/label"
    android:textSize="15px" >
</TextView>
<TextView
    android:id="@+id/addr"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@+id/label"
    android:textSize="15px" >
</TextView>

In the XXXArrayAdapter class, getView method, I set background color as below.

  private int[] colors = new int[] { 0x30FF0000, 0x300000FF };
 int colorPos = position % colors.length;
 rowView.setBackgroundColor(colors[colorPos]);

However, I do not see backgorund color filling the entire row. Please see below screenshot. Ignore red boxes, I am intentionally hiding the search results.

Upvotes: 0

Views: 304

Answers (1)

dymmeh
dymmeh

Reputation: 22306

Your layout's root LinearLayout width is set to wrap content. Set it to match_parent so it fills the entire screen

<?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:padding="5dp">

Upvotes: 1

Related Questions