这是使用 LoadManager http://developer.android.com/reference/android/app/LoaderManager.html的示例
分段适配器的示例是
私有类 SectionAdapter 扩展 SectionedAdapter {
@Override
protected View getHeaderView(String caption, int index,
View convertView, ViewGroup parent) {
TextView tv = new TextView(LazySectionListActivity.this);
tv.setText(caption);
return tv;
}
}
我对 LoadManager 的问题是我无法从单独的游标中获取日期:(,即我需要用来自两个单独游标的数据填充列表视图,并且它们应该在列表视图中用一些标题分开(就像分段适配器一样)
如何使用 LoadManager 在同一个列表视图中显示来自不同光标的数据
到目前为止,我设法在 onCreateLoader 方法中仅使用一个光标制作了可行的示例
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Uri baseUri;
baseUri = Contacts.CONTENT_URI;
String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND ("
+ Contacts.HAS_PHONE_NUMBER + "=1) AND ("
+ Contacts.DISPLAY_NAME + " != '' ))";
return new CursorLoader(getActivity(), baseUri,
CONTACTS_SUMMARY_PROJECTION, select, null,
Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
}
但我需要显示来自两个单独游标的数据
我知道我不能有两个 return 语句,但我试图说明我不知道如何解决的问题
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Uri baseUri;
baseUri = Contacts.CONTENT_URI;
String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND ("
+ Contacts.HAS_PHONE_NUMBER + "=1) AND ("
+ Contacts.DISPLAY_NAME + " != '' ))";
return new CursorLoader(getActivity(), baseUri,
CONTACTS_SUMMARY_PROJECTION, select, null,
Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
//beside the first cursor data that I want to be displayed
//I also want the date from the second cursor
Uri baseUri2;
baseUri = "some other uri";
String select2 = "some other select";
return new CursorLoader(getActivity(), baseUri2,
projection, select2, null,
MyClass.BlaBla + " COLLATE LOCALIZED ASC");
}