5

私はAndroidを初めて使用するので、この質問は単純なものかもしれません。

2つのリストを並べてレイアウトを作成しようとしています。1つのリストがある場合は正常に機能しますが、2つ目のリストを追加すると、このエラーが発生します。

私のビューは、ListActivityではなくActivityを拡張します。

しかし、ビルドがこのエラーで失敗する理由を理解できません。

\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

これは私のmain.xmlがどのように見えるかです:

<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 に答える