1

I'm working with this AlhabetScroller on GitHub https://github.com/brightec/AlphabetScroller/blob/master/src/uk/co/brightec/alphabetscroller/AlphabetListAdapter.java
There is the file 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>

My question concerns this line:
android:id="@android:id/list"

Typically, I do something like this:
android:id="@+id/my_list"

As he does with sideIndex. Instead, he uses what appears to use something that already exists in the Android code.
What is the purpose of this? Why do this instead of how I usually do?

Edit:
Thanks to Lalit Poptani. This question is indeed a duplicate.

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
  • 2
    If you are extending a **ListActivity** or a **ListFragment**, then **you must** use `android:id="@android:id/list"`. Otherwise, you are free to use any name you like (and even more than one ListView in the same Activity or Fragment!). This is a very old code: I see they still use `fill_parent` (which was deprecated on API Level **8**). And.. yes, I see they are extending ListActivity: `public class MainActivity extends ListActivity {` – Phantômaxx Jul 29 '15 at 13:17
  • 1
    Thanks for the reply. I noticed the `fill_parent` as well. Do you know of a contemporary example of this functionality? – Al Lelopath Jul 29 '15 at 13:30
  • Since API Level **8**, use `match_parent`. – Phantômaxx Jul 29 '15 at 13:45
  • Sorry, I'm not being clear. I meant functionality with respect to an alphabetized index, not fill_parent. – Al Lelopath Jul 29 '15 at 13:52
  • 1
    ... something like [this](https://github.com/emilsjolander/StickyListHeaders)? – Phantômaxx Jul 29 '15 at 14:01
  • 1
    Thanks, I'll take a look. – Al Lelopath Jul 29 '15 at 15:43

1 Answers1

1

If you use ListFragment or ListActivity you don't have to give a view, and Android has already a predefined view and an id to find it which it does automatically. Here the dev adds some stuff but to still use the ListFragment or ListActivity features, he uses the same id.

More info in ListFragment.

galex
  • 3,279
  • 2
  • 34
  • 46