2011-06-02 73 views
0

所以,這根本行不通!當我嘗試使用ListView在我的應用程序中加載佈局時,應用程序失敗並關閉!在ListView中加載佈局的問題

下面是main.xml中的佈局:

<?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"> 
    <ListView android:id="@+id/listView" android:scrollbars="none" 
       android:layout_alignParentTop="true" android:layout_height="wrap_content"    android:layout_gravity="top" android:layout_margin="0dp" android:layout_width="fill_parent" android:layout_weight="7"></ListView> 
    <LinearLayout android:layout_alignParentBottom="true" android:orientation="horizontal" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"> 
     <Button android:id="@+id/start" android:text="Start" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"></Button> 
    </LinearLayout> 
</RelativeLayout> 

和代碼的一部分,我加載此佈局:

public class main extends ListActivity { 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    ... 

我已經找了解決方案,但我只找到了案件佈局真正加載的地方。這裏的情況更糟。 該應用程序在setContentView!怎麼了?

+0

你可以發佈你的LogCat或堆棧跟蹤? – Eric 2011-06-02 22:58:18

回答

4

您正在擴展ListActivity;因此,您的ListView必須具有編號@android:id/list