Hey guys. So I have some code that, upon clicking an item on a list, creates an AlertDialog which asks you if you'd like to delete the item. For some reason, when you hit the "yes" button, the code doesn't seem to be deleting the user from the sql database. There are no errors or anything, though, in compiling or when i run the program.
Strangely, actually, the code in the "try {}" doesn't seem to be running at all. I tried putting a Toast in there, and it doesn't come up, which leads me to think the try {} code isn't executing.
Any ideas? The relevant parts of the code is below, but i can give you my full code if necessary.
Strangely, actually, the code in the "try {}" doesn't seem to be running at all. I tried putting a Toast in there, and it doesn't come up, which leads me to think the try {} code isn't executing.
Any ideas? The relevant parts of the code is below, but i can give you my full code if necessary.
Code:
lv1.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
{
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id)
{
//dialogue
final CharSequence name = ((TextView) view).getText();
AlertDialog.Builder builder = new AlertDialog.Builder(uNear.this);
builder.setMessage("Select an Option")
.setPositiveButton("User Information", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//----------------alert "user info"
}
})
.setNegativeButton("Delete User", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//alert "are you sure?"
AlertDialog.Builder subbuilder1 = new AlertDialog.Builder(uNear.this);
subbuilder1.setMessage("Are you sure you want to delete "+name+"?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//--------------------DATABASE-----------------------
SQLiteDatabase myDB = null;
try {
myDB = openOrCreateDatabase("uNearDatabase", MODE_PRIVATE, null);
myDB.execSQL("DELETE * FROM uNearTable WHERE Field1='"+name+"';");
Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
Log.e("Error", "Error", e);
}
finally
{
if (myDB != null)
myDB.close();
}
//-------------------------------------------------------------
//Toast.makeText(getApplicationContext(), name+" deleted", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
subbuilder1.show();
//end secondary alert
}
});
builder.show();
//end dialogue
return true;
}
});