2011-11-21 90 views
0

我在布局中有一个imagebutton。我想用它作为自定义对话框的启动器。但是当我点击它程序崩溃。代码即时通讯使用如下:定制对话框崩溃?

ImageButton bt = (ImageButton) findViewById(R.id.print_button); 

    bt.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      Dialog dialog = new Dialog(Details.this); 
      dialog.setContentView(R.layout.sharepopup); 
      dialog.setTitle(""); 
      dialog.setCancelable(true); 
      dialog.show(); 
      } 
    } 

这是什么错?提前致谢。

+0

Put日志猫追踪这里 –

+0

我只用用我在dialog.setContentView布局其工作不是问题检查你的布局或将日志跟踪试过你的代码。 –

+0

谢谢你们。当我把getparent()作为对话框构造函数的参数时......它运行良好。 – IronBlossom

回答

0
LayoutInflater newProject = LayoutInflater.from(Details.this); 
View projectView =newProject.inflate(R.layout.sharepopup, null); 

Dialog dialog= new Dialog(Details.this); 
dialog.setContentView(projectView); 
.... 

试试这个...

+0

它仍然无法正常工作.....但我LogCat它,并注意到dialog.show()崩溃 – IronBlossom

+0

尝试初始化主活动中的对话框,并在onClick侦听器中使用它,而不是初始化它 – Karthi