Android R类不生成ID
我有两个布局文件,一个用于主活动,另一个XML文件用于自定义列表视图的分析。我想访问布局文件中视图的ID,但在R类中,只有来自主活动XML文件的ID。我想知道如何将ID添加到R类,或者通过任何其他方式访问它们 谢谢,如果这是一个蹩脚的问题,我也很抱歉,但我对android还是相当陌生的 这是主要的活动Android R类不生成ID,android,android-layout,Android,Android Layout,我有两个布局文件,一个用于主活动,另一个XML文件用于自定义列表视图的分析。我想访问布局文件中视图的ID,但在R类中,只有来自主活动XML文件的ID。我想知道如何将ID添加到R类,或者通过任何其他方式访问它们 谢谢,如果这是一个蹩脚的问题,我也很抱歉,但我对android还是相当陌生的 这是主要的活动 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width=
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
这是布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView android:id="@+id/imgSports"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"/>
<TextView android:id="@+id/rowTitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"/>
</LinearLayout>
创建活动时,它将创建其默认布局xml。 据我所知,您希望相同的活动显示一个列表。 如果是这样,我建议您尝试将您的设计放在默认的活动布局中,这将在R中创建id。
另外,我建议您参考android开发者网站上“构建您的第一个应用程序”标题下提供的基本android教程,这将有所帮助。您了解这一点。您计划如何使用这些布局?通过创建活动或片段?应自动生成这些ID。让我们尝试清理项目或修复项目属性。是否将+号添加到id关键字?坏->安卓:id=“@id/invalidId”好->安卓:id=“@+id/validId”@VJD一个布局文件用于列表视图所在的实际活动屏幕,另一个布局文件用于列表视图行的布局