I am using an AlertDialog which displays a single choice list based on SimpleCursorAdapter:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setAdapter(cursorAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//here I need to access the selected item using a cursor
}
})
When a list item is clicked in my alert dialog, the onClick function is invoked. However, it only provides me with the position of the clicked item within the displayed list. Because I want to access my SQLite database for the selected item, I need a cursor. So, how can I call 'setOnItemClickListener' on the builder? What I need is this:
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cursor = (Cursor) parent.getItemAtPosition(position);
...
My problem is that I don't have the list object itself to call 'setOnItemClickListener'. Is there a way to retrieve the list object which is used by the AlertDialog?
Or is there another way to retrieve the cursor from only knowing the item position within the list?