I am probably just misusing the XML, but I’m trying to create a layout for a list view row, but I seem to be failing miserably.
I have this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<TextView android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/detailsTextView"
android:textSize="16sp"/>
<TextView android:id="@id/detailsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"/>
</RelativeLayout>
In hopes that I will be able to add a layout that is 100dp in height to my ListView and have two TextViews inside of it. However, when I try to set it up like so:
public View getView(int position, View currentView, ViewGroup parent)
{
View rowContents = LayoutInflater.from(mContext).inflate(R.layout.list_view_cell, null);
TextView titleView = (TextView)rowContents.findViewById(R.id.titleTextView);
titleView.setText(titles[position]);
TextView detailsView = (TextView)rowContents.findViewById(R.id.detailsTextView);
detailsView.setText(details[position]);
return rowContents;
}
It’s giving me a row with only my detailsView TextViewwith a wrap_content height, it seems. The titleView is nowhere to be seen and I would assume the rowContents isn’t being set either, otherwise the height would be 100dp, right?
I know I should be reusing the old view and setting its contents, but I just made this up quickly as a test.
What is going wrong here?
Try setting the lower TextView with
layout_belowinstead:(Otherwise you could “lock”
titleTextViewinto the upper lefthand corner, which might forcedetailsTextViewto move down.)But you should watch this Google Talk by one of Android’s lead programmers, it gives great detail on how to make an efficient adapter.