recycleしすぎてた?
[ofnhwx.olib.git] / src / jp / gr / java_conf / ofnhwx / olib / base / BaseListFragmentC.java
blob73163f4074c4c2c044a3f25a7aca5bb93f7619e9
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;
13 /**
14 * {@link ListFragment}のもと.
15 * @author yuta
17 public abstract class BaseListFragmentC extends ListFragment implements LoaderCallbacks<Cursor> {
19 protected CursorAdapter mAdapter;
21 protected abstract CursorAdapter onCreateAdapter();
23 @Override
24 public void onActivityCreated(Bundle savedInstanceState) {
25 super.onActivityCreated(savedInstanceState);
26 mAdapter = onCreateAdapter();
27 setListAdapter(mAdapter);
28 setListShown(false);
29 getListView().setFastScrollEnabled(true);
32 /**
33 * {@link #setEmptyText(CharSequence)}.
34 * @param text {@link #getText(int)}
36 public void setEmptyText(int text) {
37 setEmptyText(getText(text));
40 @Override
41 public void setEmptyText(CharSequence text) {
42 try {
43 super.setEmptyText(text);
44 } catch (IllegalStateException e) {
45 TextView ev = (TextView)getListView().getEmptyView();
46 if (ev == null) {
47 TextView tv = new TextView(getActivity());
48 tv.setText(text);
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);
55 } else {
56 ev.setText(text);
61 public void setHasContextMenu(boolean hasContext) {
62 if (hasContext) {
63 registerForContextMenu(getListView());
64 } else {
65 unregisterForContextMenu(getListView());
69 public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
70 if (getView() == null) {
71 return;
73 mAdapter.swapCursor(data);
74 if (isResumed()) {
75 setListShown(true);
76 } else {
77 setListShownNoAnimation(true);
81 public void onLoaderReset(Loader<Cursor> loader) {
82 mAdapter.swapCursor(null);