Проблема ListActivity при использовании с RelativeLayout - PullRequest
1 голос
/ 16 мая 2010

Тревога новичка, я уверен, что делаю что-то глупое здесь.

Я постепенно расширяю свой пользовательский интерфейс и хочу добавить ListView в середине моего пользовательского интерфейса. Когда я добавляю его и изменяю действие, чтобы расширить ListActivity вместо просто Activity, я получаю Force Close. Используя 1.5. Разве ListView не работает, встроенный в RelativeLayout?

Спасибо

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 выглядит так:

<?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/ImageButtonRecipes" android:src="@drawable/search"></ImageButton>
</RelativeLayout>
</RelativeLayout>

и 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>

Ответы [ 2 ]

3 голосов
/ 16 мая 2010

ListActivity должен иметь ListView с идентификатором «@ id / android: list», изменить свой идентификатор. Это работает и в RelativeLayout.

См. Listactivity для получения дополнительной информации.

0 голосов
/ 16 мая 2010

Я почти уверен, что ListActivity требует, чтобы параметр setContentView был идентификатором ListView. Попробуйте расширить просто обычную активность вместо этого.

...