Ofek Ron
Ofek Ron

Reputation: 8580

Android customized list item

I use following XML as the list item layout :

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



    <RelativeLayout
        android:id="@+id/currentUserIndicator"
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@color/blue" />

    <TextView
        android:id="@+id/workerName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/currentUserIndicator"
        android:padding="30dp"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

and it looks something like that :

enter image description here

now the problem is that when i use that on a list adapter :

    adapter = new ArrayAdapter<WorkerUser>(this, R.layout.list_item_worker, workerList) {
        @Override
        public View getView(final int position, final View convertView, final ViewGroup parent) {
            final View container;
            if (convertView == null) {
                container = inflater.inflate(R.layout.list_item_worker, parent, false);
            } else {
                container = convertView;
            }
            final TextView view = (TextView) container.findViewById(R.id.workerName);
            final View indicator = container.findViewById(R.id.currentUserIndicator);
            final WorkerUser item = getItem(position);
            view.setText(item.firstname + " " + item.lastname);
            return container;
        }
    };

it just doesnt work, the blue rectangle in the left wont show! anyone got an idea why?

Upvotes: 0

Views: 31

Answers (1)

Panther
Panther

Reputation: 9408

You have closed the RelativeLayout with 0 child in it. Since it has 0 child, its height is set to zero and hence it has disappeared. You need to put some elements inside it for it to appear or set the height in dp.
I guess you were trying to put the TextView inside the RelativeLayout, if so try this out

<RelativeLayout
android:id="@+id/currentUserIndicator"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@color/blue" >

<TextView
android:id="@+id/workerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/currentUserIndicator"
android:padding="30dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

Upvotes: 2

Related Questions