|
2 | 2 |
|
3 | 3 | import android.os.Bundle; |
4 | 4 | import android.support.v4.app.ListFragment; |
| 5 | +import android.util.Log; |
5 | 6 | import android.view.LayoutInflater; |
6 | 7 | import android.view.View; |
7 | 8 | import android.view.ViewGroup; |
@@ -34,21 +35,11 @@ public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bun |
34 | 35 | ListView lv = (ListView) layout.findViewById(android.R.id.list); |
35 | 36 | ViewGroup parent = (ViewGroup) lv.getParent(); |
36 | 37 |
|
37 | | - // Iterate through parent's children until we find the ListView, we need |
38 | | - // to do it this way as we need to find out the child index |
39 | | - for (int i = 0, z = parent.getChildCount(); i < z; i++) { |
40 | | - View child = parent.getChildAt(i); |
41 | | - |
42 | | - if (child == lv) { |
43 | | - // Remove the ListView first |
44 | | - parent.removeViewAt(i); |
45 | | - |
46 | | - // Now create ListView, and add it in it's place... |
47 | | - mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); |
48 | | - parent.addView(mPullToRefreshListView, i, lv.getLayoutParams()); |
49 | | - break; |
50 | | - } |
51 | | - } |
| 38 | + //Remove ListView and add PullToRefreshListView in its place |
| 39 | + int lvIndex = parent.indexOfChild(lv); |
| 40 | + parent.removeViewAt(lvIndex); |
| 41 | + mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); |
| 42 | + parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); |
52 | 43 |
|
53 | 44 | return layout; |
54 | 45 | } |
|
0 commit comments