Newbee 问题:下面的两个片段都可以使用,来自字符串数组或 SQLite 表中的游标。现在,如何将这些值从表中获取到字符串数组中,以便我可以操作它们,然后将它们显示为 lstAdapter?
(在添加大量评论之前,我可以提供完整的源代码,但 14 页 10 pt. 最小页眉页脚)。
我已经尝试了很多来自这里和其他地方的样品。大多数会产生我没有弄清楚的错误,休息不起作用,所以我错过了一些东西。
这种结构最终将成为我的 WIMM One 应用程序的一部分,因此它需要是 Android 版本 7。
//From my ...ListFragment:
//This works; I get "First", "Second", etc. listed on my screen:
//-----------------------
private SimpleCursorAdapter mAdapter;
private ListAdapter lstAdapter;
. . .
Log.d("RemindLF","S onCrt: NEW");
// an array of string items to be displayed
String[] strLstitems = new String[]
{"first", "Second", "Third", "Fourth"};
//
lstAdapter = new ArrayAdapter<String>(getActivity(),
R.layout.reminder_row, R.id.text1, strLstitems);
//
// Call to SetListAdapter()informs ListFragment how to fill ListView
setListAdapter(lstAdapter);
getLoaderManager().initLoader(0, null, this);
Log.d("RemindLF","X onCrt:" + strLstitems[0]);
//This also works; I get the values of one column from each record listed on my screen
//--------------------------
private ArrayAdapter aryAdapter;
. . .
Log.d("RemindLF","X onCrt: BASE" );
String[] strItems = new String[]
{
ReminderProvider.COLUMN_BODY
};
Log.d("RemindLF","X onCrt:strI:" + strItems[0]);
int[] iCnt = new int[]
{
R.id.text1
};
mAdapter = new SimpleCursorAdapter(getActivity(),R.layout.reminder_row,
null, strItems, iCnt, 0);
setListAdapter(mAdapter);
getLoaderManager().initLoader(0, null, this);
//Other pieces
//------------
//Loader set-up:
@Override
public Loader<Cursor> onCreateLoader(int ignored, final Bundle args)
{
Log.d("RemindLF","S LoadCSR");
return new CursorLoader(getActivity(), ReminderProvider.CONTENT_URI, null, null, null, null);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor)
{
Log.d("RemindLF","S LoadFin");
mAdapter.swapCursor(cursor);
}
REMINDER_LIST.XM:L
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.dummies.android.taskreminder.ReminderListFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
REMINDER_ROW.XML:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip" />