什么是“android.R.id.text1”?
我是Android开发新手。在记事本示例中,我看到了下面的代码片段:什么是“android.R.id.text1”?
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.noteslist_item, cursor,
new String[] { Notes.TITLE }, new int[] { android.R.id.text1 });
,并在notelist_item.xml
文件:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1" <-----------HERE
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:singleLine="true"
/>
所以,我想知道,这是什么android.R.id.text1
?
此外,我在android.jar
文件中发现了android.R.id.button1
,button2
,button3
。
它们是某些第三方控件的众所周知的ID吗?
由于
在Android Java框架,android.R.id.text1
是TextView
的标识符。您可以从框架中的许多布局中找到它(select_dialog_item
,select_dialog_singlechoice
,simple_dropdown_item_1line
等)。在Android框架xml中,代表@+id/text1
因此,如果您使用这些布局之一并且想要更改文本,则需要使用此ID。
#probably in a custom ListAdapter that uses
View view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
TextView textView = (textView) view.findViewById(android.R.id.text1);
textView.setText("Oh no! not hello world again");
此外,您还可以使用相同的标识符,以标识TextView
(或任何东西,但是这将是误导)在您的自定义布局。请参阅示例“记事本”,布局文件noteslist_item.xml
。
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:singleLine="true"
/>
这是一个内置的布局中使用(android.R.layout.simple_list_item_1
)视图id为默认列表等
android.R.id.text1是TextView的在机器人的预定布局定义的ID android.layout.simple_list_item1。所以就像给一个已经描述过的id而不是给出一个新的id。
我很好奇,知道它是否是[重用框架id的一个好习惯](http://*.com/questions/7082888/what- is-better-android-r-or-cutom -r) – rds 2011-08-18 21:08:05
android.R.id.text1是在notelist_item.xml中定义的TextView的ID。 您可以通过其ID找到并使用该小部件。
+1,因为它在这个问题的上下文中实际上是正确的,尽管不完整 – rds 2011-11-23 11:15:19
text1部分(和其他按钮)是您的java代码对layout.xml中定义的textView的引用。例如Android.R.id的其余部分告诉代码找到一个ID为'text1'的Android资源。
android.R.id.text1是在布局一个TextView(android.R.layout.simple_list_item_1) 您可以在
看到这个(路径UR的Android SDK)\平台\ android- \ DATA \ RES \布局
夹
android.R.id。文本1是在android 一个真正的simple_dropdown_item_1line ID,如果你对simple_dropdown_item_1line点击与CTRL +触摸板(如果你使用的笔记本电脑),你看到有使用相同的text1在XMLFILE simple_dropdown_item_1line的ID在你的xmlfile中给你的样式,然后你会很容易地运行它
我已经问过关联D问题[android.R或cutom R?](http://*.com/questions/7082888/what-is-better-android-r-or-cutom-r) – rds 2011-11-23 11:12:45
我有一个相关的问题,是吗?可能做一些像'R.id.Interger.parseInt(“someID”);'?我还没有看到一种可以使用R.id的方法,但是有没有类似的方法来做到这一点? – 2017-01-25 22:33:09