Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Passing a variable outside from AlertDialog onClick
    primarykey
    data
    text
    <p>I want to pass a variable to an outer function when user clicks on "OK" in AlertDialog. I'm trying this for example but it won't recognize the Variable (Yup).</p> <pre><code>public final void deleteBookmark(Cursor cur, int pos) { //fetching info ((Cursor) cur).moveToPosition(pos); String bookmark_id = ((Cursor) cur).getString(((Cursor) cur).getColumnIndex(Browser.BookmarkColumns._ID)); String bookmark_title = ((Cursor) cur).getString(((Cursor) cur).getColumnIndex(Browser.BookmarkColumns.TITLE)); //asking user to approve delete request AlertDialog alertDialog = new AlertDialog.Builder(Dmarks.this).create(); alertDialog.setTitle("Delete" + " " + bookmark_title); alertDialog.setIcon(R.drawable.icon); alertDialog.setMessage("Are you sure you want to delete this Bookmark?"); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { **String Yup = "yes";** } }); alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Context context = getApplicationContext(); Toast.makeText(context, "canceled" , Toast.LENGTH_SHORT).show(); } }); alertDialog.show(); **if (Yup == "yes")** { //deleting if user approved getContentResolver().delete(Browser.BOOKMARKS_URI, "_id = " + bookmark_id, null); //notifying user for deletion Context context = getApplicationContext(); Toast.makeText(context, bookmark_title + " " + "deleted" , Toast.LENGTH_SHORT).show(); } } </code></pre> <p>I know the code is a bit messed up but it's only for the sake of understanding.</p> <p>Appreciate the help!</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.
 

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