android关于如何取得listview列表里的内容,然后赋值到另一个activity。下面是部分代码,求大神指点
主activity从数据库查询数据后显示到listview列表里,然后点击listview列表的其中一项后可以跳转到另一个activity并把当前项的内容显示到这个act...
主activity从数据库查询数据后显示到listview列表里,然后点击listview列表的其中一项后可以跳转到另一个activity并把当前项的内容显示到这个activity中。下面是我写的部分主要代码。
SQLiteDatabase db = new dbhelper(DiaryList.this, "DiarBook.db", null, 1)
.getWritableDatabase();
Cursor c = db.rawQuery("select * from DiaryList", null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(DiaryList.this,
R.layout.listuse, c,
new String[] { "_id", "title", "context" }, new int[] {
R.id.titleo, R.id.titlep, R.id.titleq });
setListAdapter(adapter);
这个是提取数据库内容然后显示在列表里
list = this.getListView();
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Map<String, Object> map = (Map<String, Object>) list
.getItemAtPosition(position);
String userid = map.get("_id").toString();
String name = map.get("title").toString();
String age = map.get("context").toString();
然后利用Intent传数据我会,主要就是上面Map那里总报错,求大神啊!
}
}); 展开
SQLiteDatabase db = new dbhelper(DiaryList.this, "DiarBook.db", null, 1)
.getWritableDatabase();
Cursor c = db.rawQuery("select * from DiaryList", null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(DiaryList.this,
R.layout.listuse, c,
new String[] { "_id", "title", "context" }, new int[] {
R.id.titleo, R.id.titlep, R.id.titleq });
setListAdapter(adapter);
这个是提取数据库内容然后显示在列表里
list = this.getListView();
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Map<String, Object> map = (Map<String, Object>) list
.getItemAtPosition(position);
String userid = map.get("_id").toString();
String name = map.get("title").toString();
String age = map.get("context").toString();
然后利用Intent传数据我会,主要就是上面Map那里总报错,求大神啊!
}
}); 展开
展开全部
补充:
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
先移动光标位置到position
cursor。movetoposition(position)
再
String id = cursor.getString(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor.getColumnIndex("title"));
String age = cursor.getString(cursor.getColumnIndex("context"));
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
先移动光标位置到position
cursor。movetoposition(position)
再
String id = cursor.getString(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor.getColumnIndex("title"));
String age = cursor.getString(cursor.getColumnIndex("context"));
展开全部
你把错误贴出来可能容易看一点儿
也可以直接通过cursor来取
String id = cursor.getString(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor.getColumnIndex("title"));
String age = cursor.getString(cursor.getColumnIndex("context"));
也可以直接通过cursor来取
String id = cursor.getString(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor.getColumnIndex("title"));
String age = cursor.getString(cursor.getColumnIndex("context"));
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询