Пользовательский элемент списка для ListView Android Android?

Я программирую простой чат, используя sinch клиент.

    <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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"
                >

        <ListView
            android:id="@+id/listMessages"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:transcriptMode="alwaysScroll"

            android:layout_above="@+id/divider"
            android:padding="1dip"
            android:divider="@null"
            tools:listitem = "@layout/message_left"
            android:dividerHeight="1dp" android:stackFromBottom="true" />

У меня есть ресурс message_left в res/layout. Я хочу заполнить просмотр списка элементами message_left и message_right.

Я делаю это с

инструменты:listitem = "@layout/message_left"

В списке адаптер у меня есть следующий метод:

    if (convertView==null) {

        if(direction == DIRECTION_INCOMING){
            res = R.layout.message_left;
        }else {
            res = R.layout.message_right;
        }
        convertView = layoutInflater.inflate(res,parent,false);
    }

    WritableMessage message = messages.get(position).first;

    TextView tvMessage = (TextView) convertView.findViewById(R.id.txtMessage);
    tvMessage.setText(message.getTextBody());

    return convertView;
}

Вот сообщение message_left.xml:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp">

    <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
                    android:layout_marginRight="10dp">

        <TextView
                android:id="@+id/txtSender"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:text=""
                android:textSize="16sp"
                android:singleLine="true"
                android:layout_alignParentLeft="true"
                android:paddingLeft="10dp"
                android:paddingBottom="6dp"
                android:textColor="@android:color/black" android:textStyle="bold"/>

        <TextView
                android:id="@+id/txtDate"
                android:layout_alignParentRight="true"
                android:textColor="@color/sinch_purple"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="2dp"
                android:paddingBottom="6dp"
                android:textSize="12sp"
                android:text=""
                android:layout_alignBottom="@+id/txtSender"/>

        <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtSender"
                android:layout_alignParentLeft="true"
                android:padding="12dp"
                android:background="@drawable/grey_bubble"
                >

            <TextView
                    android:id="@+id/txtMessage"
                    android:paddingLeft="12dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/black"
                    android:textSize="14sp"
                    android:text="Hello"
                    />

        </RelativeLayout>
    </RelativeLayout>
</RelativeLayout>

Но сообщения (элементы в списке) не появляются! Любая помощь?

0 ответов

Другие вопросы по тегам