社区在Android';中使用IDs时所遵循的正确且不易出错的方法是什么;s活动xml ... ...
上面的xml代码段的TextView具有属性社区在Android';中使用IDs时所遵循的正确且不易出错的方法是什么;s活动xml ... ...,android,Android,上面的xml代码段的TextView具有属性labelFor=“@+id/costPerPerson”,其值是下面的EditText的id 我对天气惯例感到困惑,我应该使用现在的方式,还是@+id应该在EditText中使用,并且在这里以其他方式引用,如果是这样,那是什么?社区遵循的正确且不易出错的方法是什么?提前谢谢 如果您使用的是IDE及其图形布局编辑器,您可能会让它处理这些事情 如果您更多地是手工完成这项工作,长期以来的指导是将+放在布局文件中ID的第一个匹配项上,自上而下。在您的情况下,
labelFor=“@+id/costPerPerson”
,其值是下面的EditText的id
我对天气惯例感到困惑,我应该使用现在的方式,还是@+id应该在EditText中使用,并且在这里以其他方式引用,如果是这样,那是什么?社区遵循的正确且不易出错的方法是什么?提前谢谢 如果您使用的是IDE及其图形布局编辑器,您可能会让它处理这些事情
如果您更多地是手工完成这项工作,长期以来的指导是将
+
放在布局文件中ID的第一个匹配项上,自上而下。在您的情况下,costPerPerson
首先出现在txtcosperPerson
TextView
的android:labelFor
中,因此您的代码遵循此约定。这无关紧要。就我个人而言,我会给正在创建的视图加上一个加号,即它属于什么(因为+
意味着给我一个新id)。在这种情况下,EditText
。有时,由于自上而下的解析,您被迫不遵循此规则&正如我所说的,这并不重要。真正的问题是@id/camelCaseId
或@id/under\u score\u id
<RelativeLayout ..>
...
...
<Space
android:id="@+id/space4"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="@+id/numberOfPersons" />
<TextView
android:id="@+id/txtCostPerPerson"
android:labelFor="@+id/costPerPerson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/space4"
android:layout_alignBottom="@+id/costPerPerson"
android:layout_alignTop="@+id/costPerPerson"
android:gravity="center_vertical"
android:text="@string/costPerPerson"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@id/costPerPerson"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/txtCostPerPerson"
android:layout_below="@+id/space4"
android:inputType="number" />
</RelativeLayout>