In my app I have multiple markers that are added to the map and saved in SQLite, but now i want to delete a specific marker when tapping on that marker and select "delete marker" So what I have done is this:
In my LocationsDB.class
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "create table " + DATABASE_TABLE + " ( " +
FIELD_ROW_ID + " integer primary key autoincrement , " +
FIELD_LNG + " double , " +
FIELD_LAT + " double , " +
FIELD_ZOOM + " text , " +
FIELD_TITLE + " text , " +
FIELD_SNIPPET + " text , " +
" ) ";
db.execSQL(sql);
}
public long insert(ContentValues contentValues){
long rowID = mDB.insert(DATABASE_TABLE, null, contentValues);
return rowID;
}
public int del(int id){
int cnt = mDB.delete(DATABASE_TABLE, FIELD_ROW_ID+"="+id, null);
return cnt;
}
Then in my LocationsContentProvider.class
:
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
return 0;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int cnt = 0;
cnt = mLocationsDB.del(cnt);
return cnt;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
if(uriMatcher.match(uri)==LOCATIONS){
return mLocationsDB.getAllLocations();
}
return null;
}
@Override
public String getType(Uri uri) {
return null;
}
}
And then finally in my MainActivity.class
:
public void onClick(DialogInterface arg0, int arg1) {
marker.remove();
LocationDeleteTask deleteTask = new LocationDeleteTask();
deleteTask.execute();
}
})
....
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
}
class LocationInsertTask extends AsyncTask<ContentValues, Void, Void>{
@Override
protected Void doInBackground(ContentValues... contentValues) {
getContentResolver().insert(LocationsContentProvider.CONTENT_URI, contentValues[0]);
return null;
}
}
private class LocationDeleteTask extends AsyncTask<Void, Void, Void>{
@Override
protected Void doInBackground(Void... params) {
getContentResolver().delete(LocationsContentProvider.CONTENT_URI, null, null);
return null;
This initially works when selecting "delete marker" but when returning to the activity the marker then returns and doesn't get deleted?
Am not sure what i am doing wrong, so hoping someone could help me please?
Aucun commentaire:
Enregistrer un commentaire