samedi 23 mai 2015

Dealing with update from database using a list

I have a problem in dealing with update from database using a list, in edit class I have this method

list = (ListView) findViewById(R.id.list);
list.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        store store = store_List.get(position);
        Intent intent = new Intent(edit.this,Update.class);
        edit.this.finish();
        startActivity(intent);
    }
});

In Update class, I have this method:

  btnUpdate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            DB db = new DB(getApplicationContext());
            try {
                    db.open();
                    db.updatestore(HERE WHAT SHOULD I PASS);
                    adapter.notifyDataSetChanged();
                } catch (SQLiteException se) {
                    Log.e(getClass().getSimpleName(),
                            "Could not create or Open the database");
                } finally {
                    if (db != null)
                        db.close();

                }
        }
    });

In DB, the method update is as follow:

   public int updatestore(store s) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_NAME, s.getName());
    values.put(KEY_CATEGORY, s.getCategory());
    return db.update(TABLE_store, values, KEY_ID + " = ?",
            new String[] { String.valueOf(s.getEid()) });
   }

Aucun commentaire:

Enregistrer un commentaire