android - 使用安卓 :id ="android:id/list"

标签 android android-layout

<分区>

我正在 GitHub 上使用这个 AlhabetScroller https://github.com/brightec/AlphabetScroller/blob/master/src/uk/co/brightec/alphabetscroller/AlphabetListAdapter.java
有文件 list_alphabet.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:fastScrollEnabled="true" />

    <LinearLayout
        android:id="@+id/sideIndex"
        android:layout_width="40dip"
        android:layout_height="fill_parent"
        android:background="#FFF"
        android:gravity="center_horizontal"
        android:orientation="vertical" >
    </LinearLayout>

</LinearLayout>

我的问题与这一行有关:
android:id="@android:id/list"

通常,我会这样做:
android:id="@+id/my_list"

正如他对 sideIndex 所做的那样。相反,他使用的似乎是 Android 代码中已经存在的东西。
这样做的目的是什么?为什么要这样做而不是我通常做的事情?

编辑:
感谢 Lalit Poptani。这个问题确实是重复的。

最佳答案

如果您使用 ListFragment 或 ListActivity,您不必提供 View ,Android 已经有一个预定义的 View 和一个 id 来查找它,它会自动执行。开发人员在这里添加了一些东西,但为了仍然使用 ListFragment 或 ListActivity 功能,他使用了相同的 ID。

More info in ListFragment .

关于android - 使用安卓 :id ="android:id/list",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31701496/

相关文章:

android - 使用 fragment 保存 Intent ?还是 Android 打破了宇宙?

android - 如何更改布局文件中可绘制形状的颜色

android - 如何将 youtube playerview 与 scrollview 一起使用?

android - 如何在主游戏循环中播放 "randomize"动画

android - 我可以使用 WiFi 在两部未连接到路由器的安卓手机之间传输数据/消息吗?

java - 从android中的另一个类加载纹理

android - 使背景半透明

android - 可以更改 float EditText 提示的文本吗?

android - 如何在 Android 中截取屏幕截图

android - NavigationView 中的 Activity 或 fragment ?