ListActivityについて

ListViewを扱いやすくするためにListActivityというものが用意されています。

ListActivity#getListView()

    /**
     * Get the activity's list view widget.
     */
    public ListView getListView() {
        ensureList();
        return mList;
    }

    private void ensureList() {
        if (mList != null) {
            return;
        }
        setContentView(com.android.internal.R.layout.list_content);

    }

ListActivityは、mListというフィールドでListViewを持っています。これがnullの場合、setContentViewでcom.android.internal.R.layout.list_contentをセットします。ソースを「list_content.xml」で検索してみたら/core/res/res/layout/にlist_content.xmlがあったけど、これのことかな。

list_content.xml

<ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:drawSelectorOnTop="false"
    />

mListへの代入はgetListView()内には無いようです。探してみると、ListActivity#onContentChanged()にありました。名前から推測すると、setContentViewとセットで呼ばれていそうです。試しにサブクラスでonContentChangedをオーバーライドして、getListView()を複数回呼び出してみたら、推測通りgetListView()が始めて呼ばれたときだけonContentChangedが呼ばれてました。

ListActivity#onContentChanged()

    /**
     * Updates the screen state (current list and other views) when the
     * content changes.
     *
     * @see Activity#onContentChanged()
     */
    @Override
    public void onContentChanged() {
        super.onContentChanged();
        View emptyView = findViewById(com.android.internal.R.id.empty);
        mList = (ListView)findViewById(com.android.internal.R.id.list);
        if (mList == null) {
            throw new RuntimeException(
                    "Your content must have a ListView whose id attribute is " +
                    "'android.R.id.list'");
        }
        if (emptyView != null) {
            mList.setEmptyView(emptyView);
        }
        mList.setOnItemClickListener(mOnClickListener);
        if (mFinishedStart) {
            setListAdapter(mAdapter);
        }
        mHandler.post(mRequestFocus);
        mFinishedStart = true;
    }