Android ListView详解(4)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-25 11:34 点击:次
R.layout.personitem,
new String[] { "personid", "name", "age" }, new int[]{R.id.personid,R.id.personname,R.id.personage});
listView.setAdapter(simpleAdapter);
/*
* 这是通过游标在ListView控件上显示数据,需要注意的是主键字段名id应改为_id,否则会报错
Cursor cursor = personService.getRawScrollData(0, 10);
SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(this, R.layout.personitem,
cursor,
new String[] { "_id", "name", "age" }, new int[]{R.id.personid,R.id.personname,R.id.personage});
listView.setAdapter(simpleCursorAdapter);
*/
//为item选项设置监听
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
ListView listView = (ListView)parent;
Map<String,String> map = (HashMap<String, String>)listView.getItemAtPosition(position);
Log.i("DBActivity", map.get("age"));
}
});
}
}
4.业务层代码如下
Java代码
package com.lamp.service;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>