已经建好一个数据库并且在data/data/packagename/下。
现在在学习绑定了按钮监听并且查询,但是模拟到按查询button时就程序自动退出
public void onClick(View v) {
test = SQLiteDatabase.openOrCreateDatabase(
"data/data/com.example.ediantong/test.db", null);
String key = et.getText().toString();
String sql = "Select type from table22 where price="+"%"+key+"%";
Cursor c = test.rawQuery(sql,null);
c.moveToFirst();
//SimpleCursorAdapter适配器
SimpleCursorAdapter test = new SimpleCursorAdapter(test.this,
android.R.layout.simple_list_item_2,
c,
new String[] {"un", "an" },
new int[] { android.R.id.text1, android.R.id.text2 });
lv.setAdapter(test);
}
我是照着网络上代码改的,数据库有android_matadata表,table22 也有_id 主键了。