0

I have a tab activity caled "tabActivity", inside the tab activity i want a button "butDetail" at "saveImageActivity" to show a custom dialog "detail.xml". this is my code to show the dialog

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();
}

why if i add the "filepath" and "resolution" its always give "java.lang.NullPointerException", and if i detele that two variabel the dialog is show up,,, any solution for this case??

adi.zean
  • 1,085
  • 3
  • 12
  • 15

2 Answers2

2

Use following code:

TextView filepath = (TextView)dialog.findViewById(R.id.txtfilepath);
TextView resolution = (TextView)dialog.findViewById(R.id.txtresolution);
Sumit Singh
  • 15,743
  • 6
  • 59
  • 89
Mohsin Naeem
  • 12,542
  • 3
  • 39
  • 53
1

use this code

  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();
        }
Amit kumar
  • 1,585
  • 2
  • 16
  • 27