At some point, I need to queue Alertdialogs with questions to the user, waiting for him/her to answer them one by one.
The code would be something like:
for (int i=0; i<SomeValue; i++)
{
Msg = "Do you want to add " + mylist.get(i) + " to the system?";
AlertDialog ADB = new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("New document " + mylist.get(i))
.setMessage(Msg)
.setPositiveButton("Add", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Function to develop
}
})
.setNegativeButton("Ignore", null)
.show();
}
So, developing for onClick function: how do I know there which is the Alertdialog associated?
For example, how can I get to know, from the onClick function, what is the title of the current Alertdialog?
Now, you can’t access the default title so you’ll need to set the title with :
setCustomTitle(View v)– just make it a simple layout XML file with you titleTextViewin it.
Cast the
DialogInterfacetoAlertDialogin theonClick()method like this:now you can access whatever you want like that: