У меня есть очень простой диалог определяется как:Что делает диалоговое окно видимым?
import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
public class MyDialog{
private String promptReply = null; // local variable to return the prompt reply value
public String showAlert(String ignored, Context ctx)
{
LayoutInflater li = LayoutInflater.from(ctx);
View view = li.inflate(R.layout.promptdialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle("Dialog Title");
builder.setView(view);
builder.setPositiveButton("OK", (myActivity)ctx);
builder.setNegativeButton("Cancel", (myActivity)ctx);
AlertDialog ad = builder.create();
ad.show();
return "dummystring";
}
}
И когда я пытаюсь отобразить его в onCreate()
после вызывающего setContentView()
для основного макета своей деятельности, в диалог просто не показывает:
MyDialog dialog = new MyDialog();
dialog.showAlert("Why isn't this shown???", this);
С другой стороны, если я размещаю тот же самый точный вызов до, вызывающий setContentView()
для основного макета деятельности, диалог показывает, что это нормально.
Мой вопрос: почему?
Почему в этом случае критический порядок?
Что мне не хватает?