2010-08-31 69 views
2

也许我错过了一些明显的东西,但我很难为AlertDialog的主体设置自定义视图。下面是我在做来设置自定义视图什么:AlertDialog setContentView接管屏幕

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    this.setContentView(View.inflate(getContext(), R.layout.dialog_body, null)); 
} 

而不是设置AlertDialog的正文的内容,有观点被放置在整个屏幕。我如何获取视图只是为了替换AlertDialog消息正文?

+0

其onCreate函数是那个,你的活动? – 2010-08-31 00:55:41

+0

扩展AlertDialog的类。但是我使用AlertDialog.Builder。 – Gumgo 2010-09-03 06:29:40

+0

我很想有一个AlertDialog的onCreate解决方案。 – 2013-09-20 15:47:58

回答

2

您正在通过调用setContentView来设置活动的视图,这就是它占据整个屏幕的原因。你也正在做我认为是活动的onCreate方法,你需要在onCreateDialog方法中做到这一点。

继承人链接到docs和一个例子。

public Dialog onCreateDialog(int id) { 

      Dialog dialog = null; 
      AlertDialog.Builder builder = new AlertDialog.Builder(app); 
      AlertDialog alert = null; 

      builder.setTitle("A title") 
        .setCancelable(true) 
        .setView(myView); 
       alert = builder.create(); 
       return alert; 

} 
+0

它实际上是在对话框的onCreate中,但我会给它一个镜头。谢谢! – Gumgo 2010-09-01 21:14:11