2011-04-07 86 views
0

我開始在Android上並嘗試製作自定義ListView佈局。我已經按照一些導遊,並取得了以下代碼:自定義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上運行的東西。

任何想法爲什麼事情崩潰?

+2

您可以添加通過LogCat獲得的錯誤嗎? – 2011-04-07 19:35:03

回答

0

難道是因爲RelativeView不存在?

+0

謝謝,這肯定是其中的一個問題。 – 2011-04-07 19:58:16

0

我可能會建議添加屬性android:layout_width="fill_parent"android:layout_height="fill_parent"或將它們設置爲任何你想要的,但這些都是必需的。是的,馬修說,使用RelativeLayout,因爲RelativeView不存在。

0

乍一看你的textView沒有寬度/高度值?

+1

他們可以在風格中定義。 – 2011-04-07 19:39:33

+0

沒有冒犯,但「我開始在Android上」 - 我完全同意你在這 – olamotte 2011-04-07 19:41:24

+0

嗯,與應用程序崩潰它的描述似乎可能是缺乏layout_ {width,height} – 2011-04-07 19:46:06