Code example for ListFragment

Methods: getActivity, getListView, onStart

0
        return inflator.inflate(R.layout.song_view_layout, container, false);
    } 
 
    @Override 
    public void onStart() { 
        super.onStart(); 
 
        // HACK: Use device independent pixels. 
        TextView paddingView = new TextView(getActivity());
        paddingView.setHeight(120);
        getListView().addFooterView(paddingView);
        bindToMediaStore(); 
 
        setupListView(); 
    } 
 
    @Override 
    public void onAttach(Activity activity) {
        super.onAttach(activity);
 
        if (activity instanceof MediaSelectionListener) {
            mMediaSelectionListener = (MediaSelectionListener)activity;
        } 
    } 
 
    @Override 
    public void onListItemClick(ListView listView, View view, int position, long id) {
        super.onListItemClick(listView, view, position, id);
 
        if (mMediaSelectionListener != null) {
            mMediaSelectionListener.onMediaSelected((Cursor)listView.getItemAtPosition(position));
        } 
    } 
    private void setupListView() { 
        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    } 
 
    // TODO: Build a content provider to do this for us? 
    private void bindToMediaStore() { 
        mMediaCursor = getActivity().managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);