Created
May 15, 2012 14:32
-
-
Save chrisbanes/2702232 to your computer and use it in GitHub Desktop.
PullToRefreshListFragment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.handmark.pulltorefresh.library.PullToRefreshListView; | |
import android.os.Bundle; | |
import android.support.v4.app.ListFragment; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ListView; | |
public class PullToRefreshListFragment extends ListFragment { | |
private PullToRefreshListView mPullToRefreshListView; | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View layout = super.onCreateView(inflater, container, savedInstanceState); | |
ListView lv = (ListView) layout.findViewById(android.R.id.list); | |
ViewGroup parent = (ViewGroup) lv.getParent(); | |
// Iterate through parent's children until we find the ListView | |
for (int i = 0, z = parent.getChildCount(); i < z; i++) { | |
View child = parent.getChildAt(i); | |
if (child == lv) { | |
// Remove the ListView first | |
parent.removeViewAt(i); | |
// Now create ListView, and add it in it's place... | |
mPullToRefreshListView = new PullToRefreshListView(getActivity()); | |
parent.addView(mPullToRefreshListView, i, lv.getLayoutParams()); | |
break; | |
} | |
} | |
return layout; | |
} | |
protected PullToRefreshListView getPullToRefreshListView() { | |
return mPullToRefreshListView; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment