选项卡活动上的android自定义对话框

时间:2012-10-09 09:46:09

标签: android dialog customdialog

我有一个标签活动名为“tabActivity”,在标签活动中我想要一个按钮“butDetail”在“saveImageActivity”中显示一个自定义对话框“detail.xml”。这是我显示对话框的代码

public void butDetail(View v){
    final Dialog dialog = new Dialog(saveImageActivity.this);
    dialog.setContentView(R.layout.detail);
    dialog.setTitle("Detail Image");
    TextView filepath = (TextView)findViewById(R.id.txtfilepath);
    TextView resolution = (TextView)findViewById(R.id.txtresolution);
    filepath.setText("File Path : ");
    resolution.setText("Resolution : ");
    dialog.setCancelable(true);
    dialog.show();
}

为什么如果我添加“filepath”和“resolution”,它总是给出“java.lang.NullPointerException”,如果我发现那两个变量对话框出现了,,, 这种情况的任何解决方案??

2 个答案:

答案 0 :(得分:2)

使用以下代码:

TextView filepath = (TextView)dialog.findViewById(R.id.txtfilepath);
TextView resolution = (TextView)dialog.findViewById(R.id.txtresolution);

答案 1 :(得分:1)

使用此代码

  private void showDiaalog() {
            final Dialog dialog = new Dialog(Context);
            dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.layoutfile);

            dialog.setCancelable(true);
            btnok = (Button) dialog.findViewById(R.id.btnOk);

            btnok.setOnClickListener(new OnClickListener() {

                public void onClick(View arg0) {

                        //some thing else
                    }


                }
            });
            Button btnCancel = (Button) dialog.findViewById(R.id.btncancel);

            btnCancel.setOnClickListener(new OnClickListener() {

                public void onClick(View arg0) {

                    dialog.dismiss();
                }
            });

            dialog.show();
        }
相关问题