命名多个 Android 组件
Naming Multiple Android Components
我正在开发一个 Android 应用程序,但我对命名 TextView / Switch[=22= 的多个实例有点困惑]对。
我的清单文件是这样的:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/question1"
android:id="@+id/textView"
android:textColor="#212121"
android:layout_alignTop="@+id/switch1"
android:layout_alignParentStart="true" />
<Switch
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="@string/no"
android:id="@+id/switch1"
android:textColor="#616161"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
/>
问题是我将有 20 多对这样的组件,是否有任何约定来命名 UI 组件的多个实例?考虑到这些项目对的布局和顺序可能会发生变化,我不想将这些组件命名为 question1 或 switch1。我也不想给他们起非常具体和长的名字,因为在后端维护起来会更难,所以我正在寻找一种通用的方法。
如何使用介于两者之间的东西。据我所知,我想没有解决您的问题的灵丹妙药。但是您或许可以开始以 更通用的方式 给出更好的名字,如下所示。
question_label_your_age
switch_your_age
我想这样您可以使用 ide 更轻松地访问它们,并且它们会提供更多信息。
我正在开发一个 Android 应用程序,但我对命名 TextView / Switch[=22= 的多个实例有点困惑]对。
我的清单文件是这样的:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/question1"
android:id="@+id/textView"
android:textColor="#212121"
android:layout_alignTop="@+id/switch1"
android:layout_alignParentStart="true" />
<Switch
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="@string/no"
android:id="@+id/switch1"
android:textColor="#616161"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
/>
问题是我将有 20 多对这样的组件,是否有任何约定来命名 UI 组件的多个实例?考虑到这些项目对的布局和顺序可能会发生变化,我不想将这些组件命名为 question1 或 switch1。我也不想给他们起非常具体和长的名字,因为在后端维护起来会更难,所以我正在寻找一种通用的方法。
如何使用介于两者之间的东西。据我所知,我想没有解决您的问题的灵丹妙药。但是您或许可以开始以 更通用的方式 给出更好的名字,如下所示。
question_label_your_age
switch_your_age
我想这样您可以使用 ide 更轻松地访问它们,并且它们会提供更多信息。