Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dialog box or form where user can choose to enter details or cancel

Tags:

android

dialog

Within my application I would like to have a dialog box or a form appear to the user which allows the user to enter their name and telephone number.

I cannot see anything available for the user to enter details on a pop up form or dialog box. Is there any easy way to do this.

Thanks

like image 366
Tommy Avatar asked Mar 08 '11 16:03

Tommy


2 Answers

You can also stick a layout into an alert dialog using an AlertDialog.Builder, like so:

    //Preparing views
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) findViewById(R.id.layout_root));
//layout_root should be the name of the "top-level" layout node in the dialog_layout.xml file.
    final EditText nameBox = (EditText) layout.findViewById(R.id.name_box);
    final EditText phoneBox = (EditText) layout.findViewById(R.id.phone_box);

    //Building dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(layout);
    builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            //save info where you want it
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    AlertDialog dialog = builder.create();
like image 121
Cephron Avatar answered Nov 07 '22 13:11

Cephron


You can create a Custom Dialog using any layout you want.

like image 22
Robby Pond Avatar answered Nov 07 '22 12:11

Robby Pond