0

我有一个名为“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();
}

为什么如果我添加“文件路径”和“分辨率”它总是给出“java.lang.NullPointerException”,如果我删除这两个变量,对话框就会出现,,这种情况的任何解决方案?

4

2 回答 2

2

使用以下代码:

TextView filepath = (TextView)dialog.findViewById(R.id.txtfilepath);
TextView resolution = (TextView)dialog.findViewById(R.id.txtresolution);
于 2012-10-09T09:47:56.210 回答
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();
        }
于 2012-10-09T09:56:39.807 回答