3
나는 매우 간단한 대화 상자가 정의가 :대화 상자를 표시 가능하게하는 이유는 무엇입니까?
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";
}
}
내가 활동의 주요 레이아웃 setContentView()
를 호출 후 onCreate()
에 표시 할 때, 대화는 단순히 표시되지 않습니다
MyDialog dialog = new MyDialog();
dialog.showAlert("Why isn't this shown???", this);
반면에 과 정확히 일치하는 전화 번호를으로 지정하면 해당 활동의 기본 레이아웃에 대해 setContentView()
이 호출됩니다. 대화 상자에는 정상적으로 표시됩니다.
내 질문은 왜입니까?
이 경우 주문이 중요한 이유는 무엇입니까?
무엇이 누락 되었습니까? 보기를 부풀게하는 코드에