samedi 28 février 2015

Calling an AlertDialog in another class from a button onClick in another Activity

I want to call my AlertDialog "DeleteConfirm" in my Alerts.class from my AccountManager.class through a button onClick event. How do I go about this without affecting the AlertDialog's ability to delete an entry from my database.


If there are any pieces of code that are missing for reference please feel free to ask.


AlertDialog "DeleteConfirm" snippet:



public class Alerts extends Activity {



public static void ShowAccAddedAlert(Context con)
{
AlertDialog.Builder builder=new AlertDialog.Builder(con);
builder.setTitle("Add new Account");
builder.setIcon(android.R.drawable.ic_dialog_info);
DialogListener listener=new DialogListener();
builder.setMessage("Account Added successfully");
builder.setPositiveButton("ok", listener);

AlertDialog diag=builder.create();
diag.show();
}

public static AlertDialog DeleteConfirm(final Context con, final Account Acc) {


AlertDialog.Builder b = new AlertDialog.Builder(con);
b.setTitle("Account Details");
LayoutInflater li = LayoutInflater.from(con);
View v = li.inflate(R.layout.delete, null);
b.setView(v);

b.setPositiveButton("Yes", new OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
DatabaseHelper db = new DatabaseHelper(con);
db.DeleteAcc(Acc);
}
});

b.setNegativeButton("No", null);

return b.create();

}
}


AccountManager button onClick snippet:



public class AccountDetails extends Activity {


@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.accdetails);

Button delete = (Button) findViewById(R.id.delete);
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//THIS IS WHERE I WANT TO CALL MY DeleteConfirm AlertDialog
}
});
}
}

Aucun commentaire:

Enregistrer un commentaire