including list_content into list layout to retain ListFragment functionality

后端 未结 3 568
南方客
南方客 2021-02-05 11:47

First of, I\'m using The Android Compatibility Library V4 rev.3 for my 1.6(Donut)

When you first create a ListFragment it displays an indeterminant progress indicator u

3条回答
  •  生来不讨喜
    2021-02-05 12:08

    I was frustrated to see that the list_content layout was not available using the support library. My approach was simply to reuse the default onCreateView method of the ListFragment and add it as a part of my custom layout:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
    
        View listContent = super.onCreateView(inflater, container,
                savedInstanceState);
    
        View v = inflater.inflate(R.layout.my_custom_layout, container,
                false);
    
        FrameLayout listContainer = (FrameLayout) v.findViewById(R.id.my_list_container);
    
        listContainer.addView(listContent);
    
        return v;
    }
    

    I added a FrameLayout where the ListView used to be in my custom layout.

提交回复
热议问题