/** * 获取本地数据 */ private void getLocalData() { //创建或者打开数据库 createOrOpenDataBase(); // 定义一个集合用来存放我们要的几个店名 shopList = new ArrayList<Shop>(); //游标 获取数据库表单上的项 Cursor cursor = db.query("shopinfo", null, null, null, null, null, null, null); while(cursor.moveToNext()){ //第一列 就是之前定义的店名 String shopName = cursor.getString(1); Shop Shop = new Shop(shopName); shopList.add(Shop); } }
/** * 删除数据 * @param shop */ private void removeLocalData(Shop shop){ //跟据shopName查询并删除 db.delete("shopinfo", "shopName = ?", new String[]{shop.getName()}); }
修改确认键的点击监听:
builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //删除本地数据 removeLocalData(shopList.get(position)); //移除集合内的该项 shopList.remove(position); //刷新 shopAdapter.notifyDataSetChanged(); } });
原文:http://www.cnblogs.com/superdo/p/5081044.html