我有一个listView从SQLite数据库加载数据,现在我想实现一个onclicklistener到列表。当用户点击列表时,它应该将它们带到下一个活动并将相应的数据加载到TextView中。我的问题是,我将如何传递列表的数据,例如它是一个“主题”列表,并且用户点击主题“我的主页”。我想将主题“我的家”传递给下一个活动,以便我分别知道要检索哪些相应的数据。Android从SQLite数据库加载数据到下一个活动
我该怎么办?我是否将“提取”放到新的意图中?或者有另一种方式。下面是我的代码,它们显示列表视图部分:
ListView listContent = (ListView) findViewById(R.id.contentlist);
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToRead();
Cursor cursor = mySQLiteAdapter.queueAll();
startManagingCursor(cursor);
String[] from = new String[] { SQLiteAdapter.KEY_CONTENT };
int[] to = new int[] { R.id.text };
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.listrow, cursor, from, to);
listContent.setAdapter(cursorAdapter);
mySQLiteAdapter.close();
//Onclick ListView setlistener
listContent.setTextFilterEnabled(true);
listContent.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent summaryIntent = new Intent(DocumentListActivity.this, ViewDocumentActivity.class);
// summaryIntent.putExtra("SummTopic", value);
}
});
编辑: 这部分是下一个活动。
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
请帮助:
Intent i = getIntent();
extraTopic = i.getStringExtra("SummTopic");
mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
Cursor allrows = mydb.rawQuery("SELECT * FROM "+ TABLE + " WHERE topic = \" " + extraTopic + " \" " , null);
Integer cindex = allrows.getColumnIndex("topic");
Integer cindex1 = allrows.getColumnIndex("text1");
Integer cindex2 = allrows.getColumnIndex("text2");
我在从数据库中检索得到一个错误。
谢谢。
嗨,这确实有帮助。谢谢。但在下一次活动检索时出现错误。你能否帮助我在编辑过的部分中引用我的代码。谢谢 – mellissa
好的,我确实改变了我的回答 – Selvin
这完美的作品。谢谢一堆! – mellissa