Coder Social home page Coder Social logo

Comments (9)

johannilsson avatar johannilsson commented on May 28, 2024

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.

from android-pulltorefresh.

JakeWharton avatar JakeWharton commented on May 28, 2024

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.

from android-pulltorefresh.

johannilsson avatar johannilsson commented on May 28, 2024

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.

from android-pulltorefresh.

JakeWharton avatar JakeWharton commented on May 28, 2024

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.

from android-pulltorefresh.

johannilsson avatar johannilsson commented on May 28, 2024

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?

from android-pulltorefresh.

taterbase avatar taterbase commented on May 28, 2024

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

from android-pulltorefresh.

johannilsson avatar johannilsson commented on May 28, 2024

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.

from android-pulltorefresh.

ened avatar ened commented on May 28, 2024

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.

from android-pulltorefresh.

ened avatar ened commented on May 28, 2024

Or maybe keep it simply as a Gist. :) Understand it's not in the scope of this project.

from android-pulltorefresh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.