mum
mum

Reputation: 1645

How create a showdialog?

I customize a dialog as:

dialoge3 = new Dialog(this);

dialoge3.setContentView(R.layout.layoutdialoge003);

Button btnCacnel = (Button) dialoge3.findViewById(R.id.btnE3Cancel);

btnCacnel.setOnClickListener(new OnClickListener() {    
    public void onClick(View v) {
        // TODO Auto-generated method stub
        dialoge3.cancel();
    }
});

dialoge3.show();

When I click show dialog, I still can click on activity. I want that when the dialog is showing, that I can't click on the activity.

The same In C#:

Form frm=new Form ();
frm.showDialog();

Upvotes: 0

Views: 143

Answers (4)

Amit kumar
Amit kumar

Reputation: 1605

use this function and change the layout file..

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

Upvotes: 0

Google
Google

Reputation: 2223

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(R.string.dialog_fire_missiles)
               .setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       // FIRE ZE MISSILES!
                   }
               })
               .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       // User cancelled the dialog
                   }
               });
        // Create the AlertDialog object and return it
        return builder.create();

this is the simple way to make alert dailog..nd if you dont understand my code then tell me your exact problem in breief..

Upvotes: 0

Andro Selva
Andro Selva

Reputation: 54322

Try adding the below attribute. maybe it is what you are looking for,

dialoge3.setCanceledOnTouchOutside(false);

This should possibly make sure that your Dialog doesn't get cancelled when the user touches the screen outside the dialog's bounds.

Upvotes: 1

art-o-nawa
art-o-nawa

Reputation: 329

Try to use AlertDialog.Builder for your purpose. It's possible to set custom layout for your dialog with the bulder.

http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout

Upvotes: 0

Related Questions