什么是“android.R.id.text1”?

我是Android开发新手。 在记事本示例中,我看到以下代码片段:

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文件中find了android.R.id.button1button2button3

他们是一些第三方控制的一些众所周知的ID?

谢谢

在Android Java框架中, android.R.id.text1TextView的标识符。 你可以在框架的许多布局中find它( select_dialog_itemselect_dialog_singlechoicesimple_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是在android的预定义布局android.layout.simple_list_item1中定义的TextView的id。 所以就像给一个已经描述的id而不是给一个新的id。

android.R.id.text1是一个布局(android.R.layout.simple_list_item_1)中的TextView,你可以看到这个

(Android SDK的path)\ platforms \ android- \ data \ res \ layout

android.R.id.text1是在notelist_item.xml中定义的TextView的id。 你可以通过它的idfind并使用这个widget。

text1部分(和其他button)是您的java代码对layout.xml中定义的textView的引用。 Android.R.id的其余部分告诉代码find一个ID为“text1”的Android资源。

android.R.id.Text1是android中simple_dropdown_item_1line的一个实际id,如果你用ctrl + touchpad点击simple_dropdown_item_1line (如果你使用的是笔记本电脑),你会看到有一个id为simple_dropdown_item_1line,你在xmlfile中使用相同的text1,样式在你的xmlfile然后你将运行它很容易