Jeongbebs
Jeongbebs

Reputation: 4120

Can't delete data on sqlite

I'm trying to delete a single player in my database with a button.

 save.setOnClickListener(new OnClickListener(){

            public void onClick(View v) {

                db.addContact(new PlayerData(name,score));
                Log.d("Insert: ", "Inserting .."); 

            } 
      });



          load.setOnClickListener(new OnClickListener(){

                public void onClick(View v) {

                    thedb = (ArrayList<PlayerData>) db.getAllContacts();
                    String showName = db.getContact(8).getName();
                    int showScore = db.getContact(8).getscore();
                    saved.setText("Player Name: "+showName+" Player Score: "+showScore);

                } 
          });


          delete.setOnClickListener(new OnClickListener(){

                public void onClick(View v) {

                    db.deleteContact();


                } 
          });

However in delete button an error displays on db.deletecontact();

I can't figure out how to delete it since a friend of mine just gave me the code of the Database Manager.

Here is the snippet from the DatabaseManager.

    public void deleteContact(PlayerData contact) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_CONTACTS, KEY_ID + " = ?",
            new String[] { String.valueOf(contact.getID()) });
    db.close();
}

db.deleteContact(); needs an argument or parameters but i don't know what to put. Please help.

Upvotes: 0

Views: 199

Answers (2)

Harish Godara
Harish Godara

Reputation: 2386

As in load button click you are passing index of contact like

db.getContact(8).getscore();

Same as this I think you should pass in this also like

db.deleteContact(7); //index of 7th contact

Upvotes: 0

Woodi_333
Woodi_333

Reputation: 479

You need to be returning a PlayerData object. You get one of these in the load clickListener.

db.deleteContact(db.getContact(<entry number of player>));

This should provide you with the PlayerData object to pass as the parameter for the deleteContact method.

Hope this helps

Upvotes: 1

Related Questions