Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setContentView for alertDialog

working on a dialog to pop up that inside if it has two textEdit's. I would like to get the information from the text edits on submit, but dont know how. I also dont know how to do a submit or a cancel button for a plain dialog ( i know you can on an alertDialog with "setNegativeButton").

So how do I add a submit or cancel to a regular dialog? this is what I am working with thus far:

public void changeEmail(View v){

    Dialog dialog =  new Dialog(this);
    dialog.setContentView(R.layout.change_email_dialog);
    dialog.setTitle("Enter your new email");
    dialog.show();


}

I guess also I was wondering if someone could quickly explain how I would get the info from the two textEdits that are inside of the layout that the dialog is using?

like image 897
erp Avatar asked Jul 07 '26 00:07

erp


1 Answers

create a layout file: custom.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/text1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FFF" />

    <TextView
        android:id="@+id/text2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FFF"/>

</RelativeLayout>

create the following onClick function on click of the button(when you want the dialog box to appear):

button.setOnClickListener(new OnClickListener() {

          @Override
          public void onClick(View arg0) {

            // custom dialog
            final Dialog dialog = new Dialog(context);
            dialog.setContentView(R.layout.custom);
            dialog.setTitle("Title");

            // set the custom dialog components - text, image and button
            TextView text = (TextView) dialog.findViewById(R.id.text1);
            text.setText("Text view 1");

            TextView text = (TextView) dialog.findViewById(R.id.text2);
            text.setText("Text view 2");

            dialog.show();
          }
        });

Here is a link to the tutorial for getting exactly what you want.

Here is a link to a question on Stack Overflow which provides information about custom dialog box.

like image 129
Manan Dhawan Avatar answered Jul 09 '26 05:07

Manan Dhawan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!