I have the following code:
public class Events extends ListActivity {
//...
private static String[] FROM = {_ID,TIME,TITLE};
private static int[] TO = {R.id.rowid,R.id.time,R.id.title,};
private void showEvents(Cursor cursor) {
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, cursor, FROM, TO);
setListAdapter(adapter);
}
}
The R.layout.item is defined as such:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
andr开发者_Python百科oid:orientation="horizontal">
<TextView
android:id="@+id/rowid"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/rowidcolon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=": "
android:layout_toRightOf="@id/rowid" />
<TextView
android:id="@+id/time"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/rowidcolon" />
<TextView
android:id="@+id/timecolon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=": "
android:layout_toRightOf="@id/time" />
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:ellipsize="end"
android:singleLine="true"
android:textStyle="italic"
android:layout_toRightOf="@id/timecolon" />
</RelativeLayout>
So my problem is that when I run this program, the only thing that is displayed in the list is the Row ID textview. None of the text views that come after it are displayed. Does anyone know how to fix this? Thanks.
The
android:layout_width="match_parent"
android:layout_height="match_parent"
tell the row id TextView to be the same size as the parent RelativeLayout. If you want all the TextViews to be laid out horizontally you should use a LinearLayout as the parent, and set android:orientation="horizontal"
.
Try using android:layout_width="wrap_content"
for each of the TextViews although I suspect you'll also have to do other formatting to get each to be the correct width depending on if the content text length is variable.
Your TextViews should have wrap_content as their width, not match_parent. This layout is probably easier in a horizontal LinearLayout. Note that using the hierarchy viewer can sometimes make this kind of problem easy to discover.
精彩评论