1 package jp
.gr
.java_conf
.ofnhwx
.olib
.base
;
3 import android
.database
.Cursor
;
4 import android
.os
.Bundle
;
5 import android
.support
.v4
.app
.ListFragment
;
6 import android
.support
.v4
.app
.LoaderManager
.LoaderCallbacks
;
7 import android
.support
.v4
.content
.Loader
;
8 import android
.support
.v4
.widget
.CursorAdapter
;
9 import android
.view
.ViewGroup
;
10 import android
.view
.ViewParent
;
11 import android
.widget
.TextView
;
14 * {@link ListFragment}のもと.
17 public abstract class BaseListFragmentC
extends ListFragment
implements LoaderCallbacks
<Cursor
> {
19 protected CursorAdapter mAdapter
;
21 protected abstract CursorAdapter
onCreateAdapter();
24 public void onActivityCreated(Bundle savedInstanceState
) {
25 super.onActivityCreated(savedInstanceState
);
26 mAdapter
= onCreateAdapter();
27 setListAdapter(mAdapter
);
29 getListView().setFastScrollEnabled(true);
33 * {@link #setEmptyText(CharSequence)}.
34 * @param text {@link #getText(int)}
36 public void setEmptyText(int text
) {
37 setEmptyText(getText(text
));
41 public void setEmptyText(CharSequence text
) {
43 super.setEmptyText(text
);
44 } catch (IllegalStateException e
) {
45 TextView ev
= (TextView
)getListView().getEmptyView();
47 TextView tv
= new TextView(getActivity());
49 tv
.setId(android
.R
.id
.empty
);
50 ViewParent v
= getListView().getParent();
51 if (v
instanceof ViewGroup
) {
52 ((ViewGroup
)v
).addView(tv
);
54 getListView().setEmptyView(tv
);
61 public void setHasContextMenu(boolean hasContext
) {
63 registerForContextMenu(getListView());
65 unregisterForContextMenu(getListView());
69 public void onLoadFinished(Loader
<Cursor
> loader
, Cursor data
) {
70 if (getView() == null) {
73 mAdapter
.swapCursor(data
);
77 setListShownNoAnimation(true);
81 public void onLoaderReset(Loader
<Cursor
> loader
) {
82 mAdapter
.swapCursor(null);