【发布时间】:2012-09-10 11:22:17
【问题描述】:
我正在尝试使用 SQLite DB 和 Drag-Sort ListView 创建一个简单的待办事项列表应用程序。
现在我正在使用 SimpleCursorAdapter 将 SQLite 数据库游标中的数据绑定到 ListView 中,并使用 EditText 视图添加项目,如tutorial 中所述。
我已将所有内容移到一个活动中,并将普通 ListView 与 Drag-Sort ListView 交换。我的问题是将数据库和 Drag-Sort ListView 连接在一起。 DLSV 演示使用预定义的数组来填充 DSLV。
片段形式的 DSLV:
DragSortListView lv = (DragSortListView) getListView();
lv.setDropListener(onDrop);
lv.setRemoveListener(onRemove);
array = getResources().getStringArray(R.array.jazz_artist_names);
list = new ArrayList<String>(Arrays.asList(array));
adapter = new ArrayAdapter<String>(this, R.layout.list_item1, R.id.text1, list);
setListAdapter(adapter);
我现有代码的片段:
mDbHelper = new NotesDbAdapter(this);
mDbHelper.open();
...
mDbHelper.createNote(noteName, "");
fillData();
private void fillData() {
// Get all of the notes from the database and create the item list
Cursor c = mDbHelper.fetchAllNotes();
startManagingCursor(c);
String[] from = new String[] { NotesDbAdapter.KEY_TITLE };
int[] to = new int[] { R.id.text1 };
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
setListAdapter(notes);
}
谢谢你,如果这没有多大意义,我们深表歉意。
【问题讨论】:
标签: drag-and-drop android-listview android-arrayadapter listactivity android-sqlite