5

I am new to android, so maybe this question is naive.

I am trying to build a layout with two lists side by side. It works fine when I have one list, but when I add a second one, I get this error.

My view extends Activity and not ListActivity.

But I just can't figure out why my build fails with this error:

\main.xml:13: error: Error: No resource found that matches the given name (at 'id' with value '@android:id/selected_list').
\Android\android-sdk\tools\ant\build.xml:598: The following error occurred while executing this line:
\Android\android-sdk\tools\ant\build.xml:627: null returned: 1

This is what my main.xml looks like:

<ListView  
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:id="@android:id/list"
        android:layout_weight=".5"/>
    <ListView  
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:id="@android:id/selected_list"
        android:layout_weight=".5"/>
4

2 回答 2

10

使用“ @+id/list”和“ @+id/selected_list”代替“ @android:id/...”。

要在代码中找到这些 id,请使用:

findViewById(R.id.list);

或者

findViewById(R.id.selected_list);

并确保导入 R 文件:.R; 而不是 com.android.R;

于 2012-06-03T10:47:50.807 回答
3

更改列表视图的 ID

代码:

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </ListView>
    <ListView
        android:id="@+id/selected_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </ListView>
于 2012-06-03T10:51:29.223 回答