Note that there are some explanatory texts on larger screens.

plurals
  1. POGet a ContentResolver within a CursorAdapter
    primarykey
    data
    text
    <p>I've recently begun teaching myself Android development. Right now I'm making an app that shows a list of boxes; clicking on a box shows its contents. Each row view in the main list has a "delete" icon next to the box name. My ListAdapter is a subclass of <code>CursorAdapter</code>. In the <code>bindView()</code> method of <code>CursorAdapter</code>, I do the following:</p> <pre><code>@Override public void bindView(View view, Context context, Cursor cursor) { TextView name = (TextView) view.findViewById(R.id.text_box_name); name.setText(cursor.getString(cursor .getColumnIndex(DatabaseContract.BoxEntry.NAME))); name.setFocusable(false); ImageButton delete = (ImageButton) view.findViewById(R.id.button_box_delete); delete.setFocusable(false); delete.setTag(cursor.getLong(0)); delete.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { long id = ((Long) view.getTag()); } }); } </code></pre> <p>As you can see, I've tagged each ImageButton with the ID of the box it should delete. What I would like to be able to do here is this:</p> <pre><code>getContentResolver().delete(uri...); </code></pre> <p>This code would tell my custom <code>ContentProvider</code> to delete that box and all its contents. The obvious problem is that from the context of my <code>CursorAdapter</code>, I can't call <code>getContextResolver</code>. What would be the best way to go about talking to my <code>ContentProvider</code> from within the <code>CursorAdapter</code>? Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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