我正在尝试在我的片段中填充 ListView,但即使 Cursor 不是空的,因为我发现使用 log cat 时,ListView 仍然是空的。我曾尝试使用光标加载器,但这并没有帮助。光标正在从内容提供程序加载这是我的代码:
public class WisdomProverbsNormalFragment extends SherlockListFragment
implements ShowcaseView.OnShowcaseEventListener {
Context mContext;
int i;
String TAG = "#Wisdom";
boolean showAds = true;
ShowcaseView sv;
AdView adView;
static final String KEY_ITEM = "tweet";
static final String KEY_PROVERB = "proverb";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
setHasOptionsMenu(true);
View rootView = inflater.inflate(R.layout.activity_hastag_wisdom,
container, false);
mContext = getSherlockActivity();
if (haveNetworkConnection() != true) {
// Ask for internet connection
Context context = getActivity();
LayoutInflater inflaterToast = getActivity().getLayoutInflater();
View toastRoot = inflaterToast.inflate(
R.layout.toast_layout_connection, null);
Toast toast = new Toast(context);
toast.setView(toastRoot);
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
} else {
// Has connection; start service
getSherlockActivity().startService(
new Intent(mContext, GetTweetsService.class));
}
fillData();
return rootView;
}
public void fillData() {
Log.d(TAG, "Filling");
String[] projection = { WisdomDB.ID, WisdomDB.PROVERB_TITLE };
Cursor proverbs = getSherlockActivity().managedQuery(
ProverbProvider.CONTENT_URI, projection, null, null, null);
String[] from = new String[] { WisdomDB.PROVERB_TITLE };
int[] to = new int[] { R.id.textView1 };
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter dbAdapter = new SimpleCursorAdapter(mContext,
R.layout.row, proverbs, from, to);
setListAdapter(dbAdapter);
Log.d(TAG, String.valueOf(dbAdapter.getCount()));
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
Log.d("TAG", "onViewCreated");
fillData();
}
}