Get the default android ListView. - Android User Interface

Android examples for User Interface:ListView

Description

Get the default android ListView.

Demo Code


//package com.java2s;
import android.app.Activity;
import android.view.View;
import android.widget.ListView;

public class Main {
    /**//from ww  w .j  a  v  a  2s.co m
     * Get the default android list view.
     *
     * android.R.id.list, defined in xml by @android:id/list
     *
     * @param v Parent view
     * @return ListView
     */
    public static ListView androidListView(View v) {
        ListView lv = view(v, android.R.id.list);
        return lv;
    }

    /**
     * Get the default android list view.
     *
     * android.R.id.list, defined in xml by @android:id/list
     *
     * @param a Parent activity
     * @return ListView
     */
    public static ListView androidListView(Activity a) {
        ListView lv = view(a, android.R.id.list);
        return lv;
    }

    /**
     * Find a child view of any type.
     *
     * @param v Parent view
     * @param childId Child view id.
     * @return View
     */
    public static <V extends View> V view(View v, int childId) {
        return (V) v.findViewById(childId);
    }

    /**
     * Find a child view of any type.
     *
     * @param a Parent activity.
     * @param childId Child view id.
     * @return View
     */
    public static <V extends View> V view(Activity a, int childId) {
        return (V) a.findViewById(childId);
    }
}

Related Tutorials