lundi 13 juin 2016

Rearrange the database row after deleting?

i have a database in my app when i perform delete operation with the database row .row item will delete but my table keeps that empty row how can i remove this .

this is my databse:

public class ContactDatabase extends SQLiteOpenHelper {
    SQLiteDatabase db;
    public static final String DATABASE_NAME="totalContact1.db";
    public static final  String TABLE_NAME="mecontact1";
    public static final  String NAME="name";
    public static final  String PHONE="phone";
    public static final  String UID="_id";


    public ContactDatabase(Context context) {
        super(context, DATABASE_NAME, null, 1);

    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        try {
            db.execSQL("create table mecontact1" +
                    "(_id integer primary key autoincrement, name text, phone text)");
        }catch(android.database.SQLException e){
                System.out.println("table create nhi ho rha");
        }
    }
 public void deleteContact(String d,int pos){
        db=this.getWritableDatabase();
        db.delete(TABLE_NAME, UID + "= ? ", new String[] {String.valueOf(pos)}); 
}
}

when i perform "db.delete(TABLE_NAME, UID + "= ? ", new String[] {String.valueOf(pos)}); " operation in deleteContact(String d,int pos) table will keeps recode odf empty row.how will i rearrange the table with the _id column sequential.

Aucun commentaire:

Enregistrer un commentaire