|
18 | 18 | import android.os.Bundle; |
19 | 19 | import android.support.v4.app.ListFragment; |
20 | 20 | import android.view.LayoutInflater; |
21 | | -import android.view.View; |
22 | | -import android.view.ViewGroup; |
23 | | -import android.widget.ListView; |
| 21 | + |
24 | 22 | import com.handmark.pulltorefresh.library.PullToRefreshListView; |
25 | 23 |
|
26 | 24 | /** |
27 | | - * A sample implementation of how to the PullToRefreshListView with |
28 | | - * ListFragment. This implementation simply replaces the ListView that |
29 | | - * ListFragment creates with a new PullToRefreshListView. This means that |
30 | | - * ListFragment still works 100% (e.g. <code>setListShown(...)</code>). |
31 | | - * |
| 25 | + * A sample implementation of how to use {@link PullToRefreshListView} with |
| 26 | + * {@link ListFragment}. This implementation simply replaces the ListView that |
| 27 | + * {@code ListFragment} creates with a new PullToRefreshListView. This means |
| 28 | + * that ListFragment still works 100% (e.g. <code>setListShown(...)</code> ). |
| 29 | + * <p/> |
32 | 30 | * The new PullToRefreshListView is created in the method |
33 | | - * <code>onCreatePullToRefreshListView()</code>. If you wish to customise the |
34 | | - * PullToRefreshListView then override this method and return your customised |
35 | | - * instance. |
| 31 | + * {@link #onCreatePullToRefreshListView(LayoutInflater, Bundle)}. If you wish |
| 32 | + * to customise the {@code PullToRefreshListView} then override this method and |
| 33 | + * return your customised instance. |
36 | 34 | * |
37 | 35 | * @author Chris Banes |
38 | 36 | * |
39 | 37 | */ |
40 | | -public class PullToRefreshListFragment extends ListFragment { |
41 | | - |
42 | | - private PullToRefreshListView mPullToRefreshListView; |
43 | | - |
44 | | - @Override |
45 | | - public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
46 | | - View layout = super.onCreateView(inflater, container, savedInstanceState); |
47 | | - |
48 | | - ListView lv = (ListView) layout.findViewById(android.R.id.list); |
49 | | - ViewGroup parent = (ViewGroup) lv.getParent(); |
50 | | - |
51 | | - //Remove ListView and add PullToRefreshListView in its place |
52 | | - int lvIndex = parent.indexOfChild(lv); |
53 | | - parent.removeViewAt(lvIndex); |
54 | | - mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); |
55 | | - parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); |
56 | | - |
57 | | - return layout; |
58 | | - } |
59 | | - |
60 | | - /** |
61 | | - * @return The {@link PullToRefreshListView} attached to this ListFragment. |
62 | | - */ |
63 | | - public final PullToRefreshListView getPullToRefreshListView() { |
64 | | - return mPullToRefreshListView; |
65 | | - } |
| 38 | +public class PullToRefreshListFragment extends PullToRefreshBaseListFragment<PullToRefreshListView> { |
66 | 39 |
|
67 | | - /** |
68 | | - * Returns the {@link PullToRefreshListView} which will replace the ListView |
69 | | - * created from ListFragment. You should override this method if you wish to |
70 | | - * customise the {@link PullToRefreshListView} from the default. |
71 | | - * |
72 | | - * @param inflater |
73 | | - * - LayoutInflater which can be used to inflate from XML. |
74 | | - * @param savedInstanceState |
75 | | - * - Bundle passed through from |
76 | | - * {@link ListFragment#onCreateView(LayoutInflater, ViewGroup, Bundle) |
77 | | - * onCreateView(...)} |
78 | | - * @return The {@link PullToRefreshListView} which will replace the |
79 | | - * ListView. |
80 | | - */ |
81 | 40 | protected PullToRefreshListView onCreatePullToRefreshListView(LayoutInflater inflater, Bundle savedInstanceState) { |
82 | 41 | return new PullToRefreshListView(getActivity()); |
83 | 42 | } |
|
0 commit comments