Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

AlertDialog How to get the click result in outer class?  RSS feed

Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day to All! I'll try to describe my question. It's something in architecture I believe. So, let's start.
I have an activity where the user can create new player or click "list" and get the list of already created players. So in I create DatabaseHelper and SQLiteDatabase and use it for INSERT (if new player) or SELECT (if the player choose the existing one). To fill the list I use "ListView" and "Adapter".
When user click (shortly) on the player name in the list, he get the AlertDialog with question "Do you want to proceed with player XXX?" If NO I simply cancel, if YES I take the name, create "intent" and start another activity with player name transferred (intent.putExtra("name", LoginDialog.selectedName)) to that another activity. That's quite good. But now I want to allow user to delete player. The idea is - after a long click user get AlertDialog with question "Do you really want to delete player XXX?" NO - it's clear - cancel. But how to cope with YES?

Roughly - after YES I have to connect to DB and perform DELETE query. How I tried:

public class DeleteDialog {
AlertDialog.Builder ad;
public static Context context;
public static String selectedName;
public DatabaseHelper mDatabaseHelper;
public SQLiteDatabase mSqLiteDatabase;
public void dialogOfSelectedName(Context context, String selectedName){

ad = new AlertDialog.Builder(context);
ad.setTitle("Удаление игрока");
ad.setMessage("Удалить игрока " + selectedName + "?");
mDatabaseHelper = new DatabaseHelper(context, "mydatabase.db", null, 1);
mSqLiteDatabase = mDatabaseHelper.getWritableDatabase();
ad.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mSqLiteDatabase.execSQL("DELETE FROM" + DatabaseHelper.DATABASE_TABLE + " WHERE " + DatabaseHelper.NAME_COLUMN+" LIKE '"+selectedName+ "'");


ad.setPositiveButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

AlertDialog alert = ad.create();;


The problem is "selectedName" cannot be seen from overridden method "onClick" but I need it in the query. How to realize it? Or my approach is totally wrong? Plese, help with advice.
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
Thread Boost - a very different sort of advertising
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!