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 :
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();
}
});
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.
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.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With