port to ListFragment?
ened opened this issue · 9 comments
Hi there,
is a port to the new ListFragment paradigm planned?
Thanks,
Sebastian
Hi, I haven't had time to read up much on Fragments. What would be the benefits to use fragments here? Sorry if it's obvious but I guess it would get me started faster if I can get the big picture direct.
ListFragment
(like ListActivity
) is just a thin veil around a ListView
with some helper methods so providing your own pull refresh version is probably outside the scope of this library.
That's not so say that it wouldn't be useful for an individual making an app. To roll your own, copy the source of ListFragment
from the compatibility library and replace its ListView
instantiation with this library. It should be fairly easy.
Thank you Jake, will look into it and see if there's a point wrapping it, just don't want to end up wrapping it and maintaining something that's not really a part of this project.
However reading the docs for ListFragment
there's seems to be an example on how to provide your own layout. It might work to just provide a layout with the PullToRefreshListView
since it's compatible with ListView
.
That's true and a good solution for using native Fragments on 3.0+. If you are using the compatibility library a word of caution: make sure you are using the IDs defined in the ListFragment
class and not android.R.id.list
or you'll get some wonky errors.
Thanks for the heads up it seems like you have to use @id/android:list
when using a custom layout. Have you or someone else done a write up of the problems using this ID with ListFragment
?
Hey, I was able to use your library in a fragment using the method described in this post. Thanks for the great lib! http://stackoverflow.com/questions/8648040/how-to-implement-pull-to-refresh-on-a-listfragment
Thank you for the update. Would you mind setting up the needed fixes in a pull request and I would be happy to merge it.
Hi,
It's not that simple unfortunately.
ListFragment comes with methods to hide/show the list when busy and show a progress indicator while loading.
This mechanism requires a custom view hierarchy returned from the 'onCreateView' method. In fact it's a FrameLayout with views for the progress, empty text etc.
The idea is to override that onCreateView and replace the default ListView with a PullToRefresh ListView.
Here is the code that works now:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup viewGroup = (ViewGroup) super.onCreateView(inflater, container, savedInstanceState);
View lvOld = viewGroup.findViewById(android.R.id.list);
final PullToRefreshListView listView = new PullToRefreshListView(getActivity());
listView.setId(android.R.id.list);
listView.setLayoutParams(new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
listView.setDrawSelectorOnTop(false);
FrameLayout parent = (FrameLayout) lvOld.getParent();
parent.removeView(lvOld);
lvOld.setVisibility(View.GONE);
parent.addView(listView, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return viewGroup;
}
@johannilsson You could ship with a sample PullToRefreshListFragment that inherits from ListFragment. People could change the import or switch to SherlockListFragment if they want.
Or maybe keep it simply as a Gist. :) Understand it's not in the scope of this project.