开发者

ListActivity problem when using with RelativeLayout

Newb alert, I'm sure I'm doing something dumb here.

I've been progressively expanding my UI, and I want to add a ListView in the middle of my UI. When I add it and change the activity to extend a ListActivity instead of just an Activity, I'm getting a Force Close. Using 1.5. Does a ListView not work embedded in a RelativeLayout?

Thanks

public class Categories extends ListActivity{

final static String[] ITEMS = {"blah", "floop", "gnarlp", "stuff"};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.categories);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                R.layout.listrow, R.id.textview, ITEMS);
        setListAdapter(adapter);

XML looks like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
 <ImageView 
  android:id="@+id/ImageView01" 
  android:layout_height="fill_parent" android:layout_width="fill_parent" android:scaleType="center" android:background="@drawable/background">
 </ImageView>
 <ImageView android:id="@+id/ImageView02" android:src="@drawable/cat_heading" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerHorizontal="true">
  </ImageView>
<ListView android:id="@+id/ListView01" android:layout_below="@id/ImageView02" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView>
<RelativeLayout android:id="@+id/RelativeLayout02" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignBottom="@+id/RelativeLayout01" android:layout_centerHorizontal="true">
<ImageButton android:id="@+id/ImageButtonRecipes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:src="@drawable/recipes"></ImageButton>
<ImageButton android:id="@+id/ImageButtonSearch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_toRightOf="@+id/ImageButtonRec开发者_JAVA技巧ipes" android:src="@drawable/search"></ImageButton>
</RelativeLayout>
</RelativeLayout>

and the listrow.xml:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textview"/>
</LinearLayout>


A ListActivity must have a ListView with the ID "@id/android:list", change your ID. It works in a RelativeLayout too.

See Listactivity for further info.


I'm pretty sure a ListActivity needs the setContentView parameter to be a ListView Id. Try extending just a regular Activity instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜