Torewin Torewin - 2 months ago 11
Android Question

Android show AlertDialog on popup Activity

I am trying to add an

AlertDialog
to popup from a popup Activity (which is an Activity that extends Activity with
android:theme="@android:style/Theme.Dialog"
in the Manifest. I am using:

Context context = getApplicationContext();
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Add Extra");
final EditText base = new EditText(builder.getContext());
final EditText value = new EditText(builder.getContext());
base.setHint("Name");
value.setHint("Value");
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
base.setInputType(InputType.TYPE_CLASS_TEXT);
value.setInputType(InputType.TYPE_CLASS_TEXT);
layout.addView(base);
layout.addView(value);
builder.setView(layout);
builder.setMessage("")
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {

}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
AlertDialog dialog = builder.create();
dialog.show();


to create my Alert, but I recieve an error about not having the correct context. Is there a specific way to get the context of the popup dialog?

Answer Source

Android AlertDialog in Activity Dialog.Theme

I asked this question again and it was answered for anyone else having this problem.