以下是使用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");
}
但我需要显示来自两个单独游标的数据
我知道我不能有两个返回语句,但我试图说明我不知道如何解决它的问题
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");
}