Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling delete method in custom content provider
    primarykey
    data
    text
    <p>I am learning Android and I am stuck on an issue involving calling a custom content provider. I have been using an example in an instructional book and although it describes how to create the custom provider there is no clear example how to call the specific methods in it. I am specifically looking into how to delete a single record from the custom content provider.</p> <p>Here is the code for the custom content provider (<code>EarthquakeProvider.java</code>):</p> <pre><code>@Override public int delete(Uri uri, String where, String[] whereArgs) { int count; switch (uriMatcher.match(uri)) { case QUAKES: count = earthquakeDB.delete(EARTHQUAKE_TABLE, where, whereArgs); break; case QUAKE_ID: String segment = uri.getPathSegments().get(1); count = earthquakeDB.delete(EARTHQUAKE_TABLE, KEY_ID + "=" + segment + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs); break; default: throw new IllegalArgumentException("Unsupported URI: " + uri); } getContext().getContentResolver().notifyChange(uri, null); return count; } </code></pre> <p>I am trying to call the delete method from the main activity to delete a single entry, not the entire database. I want to use about an <code>OnLongClickListener</code> for the selected record that is displayed in a array list view in the main activity.</p> <p>This is what I have come up with I have so far in my main activity for this method:</p> <pre><code>earthquakeListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView _av, View _v, int _index, long arg3) { ContentResolver cr = getContentResolver(); cr.delete(earthquakeProvider.CONTENT_URI, null, null); return false; } </code></pre> <p>I know the above code doesn't work, but this is as close as I could get with my current understanding.</p> <p>Any help on this would be very much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload