开发者

Android: is forcing to use ListView

I want to make a menu, which contains 4 different LinearLayouts. Top one has title, second one has description, the third one has 3 ImageViews, which have event onClick, and the fourth one has a Button which also has onClick event.

Somehow, android doesn't like it, and forcing me to use ListView.

The exception message is: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

I have already tried to use ListView, and it didn't work as I expected. For example, the 3rd layout, which has 3 buttons, the events are not working for each ImageView, but instead on the row of the ListView.

What can be done?

Displaying my layouts xml files:

options.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/optionsLa开发者_运维知识库yout"
    android:background="@drawable/bg" android:layout_gravity="center">

    <include  layout="@layout/options_layout1" android:id="@+id/optionsLayout1" />
    <include  layout="@layout/options_layout2" android:id="@+id/optionsLayout2" />
    <include  layout="@layout/options_layout3" android:id="@+id/optionsLayout3" />
    <include  layout="@layout/options_layout4" android:id="@+id/optionsLayout4" />

</LinearLayout>

options_layout1.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:id="@+id/optionsTitleLayout"
    android:background="@drawable/options" 
    android:layout_gravity="center" />

options_layout2.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:id="@+id/chooseThemeTitleLayout"
    android:background="@drawable/choose_theme" android:layout_gravity="center" 
    android:layout_marginTop="70dip" />

options_layout3.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:id="@+id/optionButtonsLayout" 
    android:layout_gravity="center" android:layout_marginTop="10dip" >
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/theme1Btn"
        android:background="@drawable/theme1_off" android:layout_marginLeft="10dip" 
        android:layout_marginRight="10dip" />
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_centerInParent="true"
        android:id="@+id/theme2Btn" android:background="@drawable/theme2_off" 
        android:layout_marginLeft="10dip" android:layout_marginRight="10dip" />
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_toRightOf="@id/theme2Btn"
        android:id="@+id/theme3Btn" android:background="@drawable/theme3_off" 
        android:layout_marginLeft="10dip" android:layout_marginRight="10dip"/>
</LinearLayout>

options_layout4.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:id="@+id/saveButtonLayout"
    android:layout_gravity="center" >
    <Button android:id="@+id/saveBtn" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_centerHorizontal="true"
        android:text="Save" android:layout_marginTop="10dip"/>
</LinearLayout>

Thanks, Henry.


The problem is not the xml, the problem is somewhere in the code. You use a specific class which expects an ID R.id.list to be in your layout. Probably your Activity still extends ListActivity? This Activity needs an R.id.list in it's layout.


Are you using a ListActivity? If so, just replace it for Activity.


If you extends your activity as ListActivity ,you have to listview with android:id="@android:id/list"

otherwise extends your activity as Activity and and get listview :
Listview list = (Listview) findViewById(R.id.mylist);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜