按钮alertDialog未显示 [英] button not shown in alertDialog

查看:114
本文介绍了按钮alertDialog未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我米创建扩展AlertDialog类。和设置布局。但是,当弹出被调用时,

I m creating a class that extends AlertDialog. and setting layout. But when pop up is called,

** 1)布局是透明的。

**1) layout is transparent

2)的按钮不可见甚至称SET按钮后**
我不知道该怎么做的,不知道为什么它的发生。

2) buttons not visible even after calling setButton ** I don't know what to do with , and no Idea why its happening.

我的班是这个
DateTimeDialog.java

My classes are this DateTimeDialog.java

public class DateTimeDialog extends AlertDialog{

    Date date;
    String title;
    DialogInterface.OnClickListener listner;
    protected DateTimeDialog(Context context, String title, Date date ) {
        super(context);
        // TODO Auto-generated constructor stub
        this.title = title;
        this.date = date;
    }

    public void initListener(DialogInterface.OnClickListener listner){
        this.listner = listner;
    }

    public Date getDate(){


        return date;
    }


    @Override
    public void onCreate(Bundle savedInstanceState){
        //super.onCreate(savedInstanceState);
        setContentView(R.layout.date_time_picker);



        setTitle(title);

        setButton( "OK", listner);

        setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",
                new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Do something
                        dialog.dismiss();
                    }
                });

    }

方法被调用这个类

method that is calling this class

final DateTimeDialog dateTimeDialog = new DateTimeDialog(context, "title", time);
           dateTimeDialog.show();
           dateTimeDialog.initListener(new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    //doSomething
                }
            });

请帮忙.....

推荐答案

当你调用的setContentView,你重写AlertDialog类提供任何及所有内容。如果你想设置内容查看你自己,你需要添加的按钮在XML文件中,并设置监听器。

When you call setContentView, you override any and all content the AlertDialog class provides. If you want to set the content view yourself, you need to add the buttons in the XML file and set listeners.

这篇关于按钮alertDialog未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆