masmic
masmic

Reputation: 3574

Implementing custom dialog

I'm implementing a custom dialog, but in the activity, I'm having a trouble. This is the code:

public class MainActivity extends Activity {

private Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    button = (Button) findViewById(R.id.buttonDialog);

    /*Add button listener*/
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            /*Custom dialog*/
            final Dialog dialog = new Dialog(this);
            dialog.setTitle("Cerrar App");
            dialog.setContentView(R.layout.custom_dialog);

        //...

In the line final Dialog dialog = new Dialog(this); it's throwing me an error that says: The constructor Dialog(new View.OnClickListener(){}) is undefined.

What I'm doing wrong?

Upvotes: 0

Views: 116

Answers (3)

Dakshesh Khatri
Dakshesh Khatri

Reputation: 629

Dialog videoDialog = new Dialog(getApplicationContext());
videoDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
videoDialog.setContentView(R.layout.video_dialoge);

videoDialog.getWindow().setGravity(
        Gravity.BOTTOM | Gravity.CENTER_VERTICAL);

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = videoDialog.getWindow();
lp.copyFrom(window.getAttributes());
lp.width = WindowManager.LayoutParams.FILL_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
LinearLayout frmalbumb = (LinearLayout) videoDialog
        .findViewById(R.id.layout_album);
LinearLayout frmcamera = (LinearLayout) videoDialog
        .findViewById(R.id.layout_camera);
frmcamera.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v)
    {
        Intent cameraIntent = new Intent(
                android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
        startActivityForResult(cameraIntent, capturevideo);
        videoDialog.dismiss();
    }
});
frmalbumb.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent mediaChooser = new Intent(Intent.ACTION_GET_CONTENT);
        mediaChooser.setType("video/*");
        startActivityForResult(mediaChooser, galleryVideo);
        videoDialog.dismiss();
    }
});

WindowManager.LayoutParams wmlp = videoDialog.getWindow()
        .getAttributes();
wmlp.gravity = Gravity.BOTTOM;
wmlp.x = (img_btn_Video.getLeft() + (img_btn_Video.getLeft() / 2));
if (CommonUtilities.istablet == true) {
    wmlp.y = 69;
} else {
    if (CommonUtilities.screen_height >= 1920) {
        wmlp.y = 130;
    }else if(CommonUtilities.screen_height<=854)
    {
        wmlp.y = 75;
    }
    else {
        wmlp.y = 90;
    }
}
videoDialog.getWindow().setBackgroundDrawable(
        new ColorDrawable(android.graphics.Color.TRANSPARENT));
    videoDialog.show();

Upvotes: -2

vipul mittal
vipul mittal

Reputation: 17401

change:

final Dialog dialog = new Dialog(this);

to

final Dialog dialog = new Dialog(MainActivity.this);

Upvotes: 4

Blackbelt
Blackbelt

Reputation: 157487

Change

final Dialog dialog = new Dialog(this);

with

final Dialog dialog = new Dialog(MainActivity.this);

in your case this refers to inner onClickListener

Upvotes: 6

Related Questions