Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data from a custom dialog box

Tags:

android

dialog

I Have a dialoge box in my code, that when i click a button in Main activity it pops up, this dilog box is like this :

enter image description here

I want to put String data from "Enter NUmber" and "Enter Name" Test box to a viewText in Main Activity, I don't know how to transfer this value. my part of code which pops up dialog box is this :

btnstart.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Auto-generated method stub
            final Dialog dialog = new Dialog(Main0.this);
              dialog.setContentView(R.layout.number);
              dialog.setTitle("Save New Number");
              dialog.setCancelable(true);   
              dialog.show();


        }
    });
like image 539
Reza_Rg Avatar asked Dec 01 '12 21:12

Reza_Rg


People also ask

How to get data from dialog box?

If the textView, where you want to show the text, is in the same Activity, where the dialog pops, define a String like: String text=""; then, get the textView (inside onClick before dialog. show())of Your in xml defined dialog layout.

How pass data from activity to dialog fragment in Android?

In order to pass the data to the DialogFragment class, we can simply set the data using setArguments on the instance of the class. In order to return the data from the DialogFragments to the Activity/another fragment, we need to create our custom interface.

How to display dialog box in android?

Alert Dialog code has three methods:setTitle() method for displaying the Alert Dialog box Title. setMessage() method for displaying the message. setIcon() method is used to set the icon on the Alert dialog box.

What is custom dialog in Android?

The custom dialog uses DIALOG to create custom alert in android studio. Dialog display a small window i.e a popup which draws the user attention over the activity before they continue moving forward. The dialog appears over the current window and display the content defined in it.


1 Answers

This should work:

Button saveButton = (Button)dialog.findViewById(R.id.saveButton);
saveButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
        String name = ((EditText)dialog.findViewById(R.id.nameText)).getText().toString();
        String number = ((EditText)dialog.findViewById(R.id.numberText)).getText().toString();
    }
});

(Add it in your onClick method)

like image 165
Jong Avatar answered Sep 19 '22 08:09

Jong