【发布时间】:2011-08-16 18:08:31
【问题描述】:
当我开始开发 android 应用程序时,我倾向于在任何需要的地方定义自定义 R 值,尤其是在布局文件中。例如:
findViewById(R.id.customerName).setText(customer.getName())
带布局:
<TextView android:text="TextView" android:id="@id/customerName"
android:layout_height="wrap_content" android:layout_width="fill_parent" />
现在我意识到,改用android.R 可能会更好。
findViewById(android.R.id.text1).setText(customer.getName())
带布局:
<TextView android:text="TextView" android:id="@android:id/text1"
android:layout_height="wrap_content" android:layout_width="fill_parent" />
你遵循什么做法?各有什么优缺点?
【问题讨论】:
-
自定义也...我认为使用自己的东西比使用本机操作系统更好。您无法以任何方式控制它
-
我不明白。当我使用自定义标识符时,我可以获得什么样的控制权?
-
android:id="@android:id/customerName"- 这是正确的吗?正如它所写的那样,customerName似乎是在 Android SDk 的顶层定义的 id,但事实并非如此;你想说android:id="@+id/customerName?? -
@保罗。绝对正确。复制/粘贴错误。
标签: android coding-style convention