-1

I have been trying to implement a LongClick on my database for quite some time, but for now it is only a short click that works. I'm writing in android an I have a database that I am trying to delete records from. Here's my code so far,

protected void onListItemClick(ListView l, View v, int position, long id) {
    @SuppressWarnings("unchecked")
    //THIS IS TO DELETE FROM DATABASE, NEED TO IMPLEMENT LONGCLICK
    Vehicle toDelete = ((ArrayAdapter<Vehicle>) l.getAdapter()).getItem(position);
    VehicleDataSource vds = new VehicleDataSource(this);
    vds.deleteVehicle(toDelete);
    getLoaderManager().restartLoader(0, null, this);

}

Heres my delete vehicle method in my VehicleDataSource class,

  public synchronized void deleteVehicle(Vehicle v) throws SQLException {
      SQLiteDatabase db = dbHelper.getWritableDatabase();
      db.delete(MySQLiteHelper.TABLE_VEHICLE, 
              MySQLiteHelper.COLUMN_ID + " = ?", new String[] {v.getId() + ""});
  }

If anyone could give me any tips or any help that would be greatly appreciated. Thanks.

1 Answers1

0

Set an OnItemLongClickListener on your ListView, then handle interactions with the selected view in your on boolean onItemLongClick (AdapterView<?> parent, View view, int position, long id) method. It might be worth checking out the documentation on handling input events.

Submersed
  • 8,810
  • 2
  • 30
  • 38