当我开始开发安卓应用程序时,我有一个习惯,在需要的地方(特别是在布局文件中)定义自定义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"
吧? - Paul