自定义ListView布局崩溃了我的活动

时间:2011-04-07 19:32:24

标签: android

我开始使用Android并尝试制作自定义ListView布局。我已经按照一些指南编写了以下代码:

public class CheckInList extends ListActivity {
...
    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        mAdapter = new ArrayAdapter<String>(this, R.layout.checkinlist_item, R.id.checkinlist_item_text, mNames);
        setListAdapter(mAdapter);
        ...
    }
}

这是checkinlist_item.xml的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeView xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="@drawable/checkinlist_item_bg">
    <TextView android:id="@+id/checkinlist_item_text"
              style="@style/RegisterText" />
</RelativeView>

如果我使用android.R.layout.simple_list_item_1而不是我的上面的模板,那么一切都很好,我的ListView工作,但每当我使用上面的代码我的活动崩溃。我在Android 1.5上运行。

为什么事情崩溃的任何想法?

3 个答案:

答案 0 :(得分:0)

可能是因为RelativeView不存在吗?

答案 1 :(得分:0)

我可能会建议添加属性android:layout_width="fill_parent"android:layout_height="fill_parent"或将它们设置为您想要的任何内容,但这些都是必需的。是的,使用RelativeLayout正如Matthew所说,因为RelativeView不存在。

答案 2 :(得分:0)

乍一看,textView没有宽度/高度值?