Code example for ListFragment

Methods: getActivity, onCreateView, setListAdapter

0
    public View onCreateView(
        LayoutInflater inflater,
        ViewGroup container,
        Bundle b)
    { 
        View view = super.onCreateView(inflater, container, b);
 
        installListAdapter(getActivity());
 
        return view;
    } 
 
    /** 
     * @see android.support.v4.app.ListFragment#onListItemClick(android.widget.ListView, android.view.View, int, long) 
     */ 
    @Override 
    public void onListItemClick(ListView l, View v, int pos, long row){
        Cursor cursor = (Cursor) getListAdapter().getItem(pos);
        Log.d("####", "Got click at: " + pos);
 
        String id = cursor.getString(
            cursor.getColumnIndex(BaseColumns._ID));
        String name = cursor.getString(
            cursor.getColumnIndex(Contacts.DISPLAY_NAME));
 
        Intent intent = new Intent();
        intent.setClass(getActivity(), ContactDetailActivity.class);
        intent.putExtra(ContactDetails.TAG_ID, id);
        intent.putExtra(ContactDetails.TAG_CONTACT, name);
        startActivity(intent);
    } 
 
    private void installListAdapter(Activity activity) {
        setListAdapter(
            new ContactsCursorAdapter( 
                activity,
                activity.managedQuery(
                    Contacts.CONTENT_URI,
                    CONTACTS_PROJECTION,