public void setlist(String q) {
try {
SQLiteDatabase db = openOrCreateDatabase(Config.DB_DATABASE,
Context.MODE_PRIVATE, null);
//查询
Cursor cursor = db
.rawQuery(
"select *,(select check_result from t_checkresultdetail where declaration_no=a.declaration_no "
+ "and check_item_no=a.check_item_no) check_result, (select handle_view from t_checkresultdetail"
+ " where declaration_no=a.declaration_no and check_item_no=a.check_item_no) handle_view from"
+ " T_CheckPlanDetail a,T_Dict_CheckItem b where a.check_item_no=b.serial_no and declaration_no=?"
+ " and attribute_entry_id=?",
new String[] { "ALAMA201506W0131", q });
ListView listView = (ListView) findViewById(R.id.lv1);
List<Map<String, String>> contents = new ArrayList<Map<String, String>>();
ContentValues values = new ContentValues();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor
.moveToNext()) {
Map<String, String> map = new HashMap<String, String>();
map.put("abc1", "检查项目");// 检查项目
map.put("abc2", "检查结果");// 检查结果
map.put("abc3", "处理意见");// 处理意见
map.put("abc4", cursor.getString(cursor
.getColumnIndexOrThrow("item_name")));// 项目名称item
// name
map.put("abc5", cursor.getString(cursor
.getColumnIndexOrThrow("check_result")));// 检查结果check result
map.put("abc6", cursor.getString(cursor
.getColumnIndexOrThrow("handle_view")));// 处理意见handle view
map.put("abc7", cursor.getString(cursor
.getColumnIndexOrThrow("attribute_kinds_name")));// 二级检查项目名称attribute
// kinds
// name
map.put("abc8", cursor.getString(cursor
.getColumnIndexOrThrow("norms_code_a")));// 规则及守则A编码norms
// code
// a
map.put("abc9", cursor.getString(cursor
.getColumnIndexOrThrow("norms_code_b")));// 守则B编码norms
// code
// b
map.put("abc10", "整改措施");// 整改措施
map.put("abc11", "验证结果");// 验证结果
map.put("abc12", "");// 整改措施reform meas
map.put("pass_flag", "");// 验证结果pass_flag
contents.add(map);
values.put("check_result",map.get("abc5"));
values.put("handle_view",map.get("abc6"));
db.insert("T_CheckResultDetail", null, values);
System.out.println(values.get("check_result"));
}
db.close();
LuruAdapter newAdapter = new LuruAdapter(this, contents);
listView.setAdapter(newAdapter);// 为listview添加配适器
} catch (Exception e) {
e.printStackTrace();
}
}
本意是想先把值放到map中读出来,然后再通过ContentValues把check_result与handle_view选择的值存到数据库中,方便实现之后的回调,但是不知道为什么运行的时候一直提示插入错误,主键不是唯一的,_(:з」∠)_求解。
------解决思路----------------------
日志说插入为空,debug看下values