Problem loading layout in ListView
So, this simply doesn't work! When I try to load a layout inside my app using ListView, the application fails and closes!
Here is the layout for 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="wr开发者_高级运维ap_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>
And the part of the code I load this layout:
public class main extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...
I've looked for solutions but I only found the cases where the layout is really loaded. The situation here is worse. The application fails right in setContentView! What's wrong?
You're extending ListActivity; thus, your ListView must have the id @android:id/list
.
精彩评论