Hello all……
This post examples how to get an edittext value from a dialog fragment.
You can use the same method to get a button click from a dialog or events like that.
You can click on the download link to get the source code.
At first we will create a layout for the Dialog Fragment.
The layout contains only an editext. We are getting this edittext value from the fragment to the activity when the “DONE” button is clicked after inputting text.
frag_edit_name.xml
Next we will write the class for the DialogFragment.
MyDialogFragment is my class name for the DialogFragment.
MyDialogFragment.java
OK Now our fragment is complete.
Here we use interface to get value from the editext in the DialogFragment.
This is the interface which has only one method
onFinishEditDialog
Now we implement this interface in the activity and call the method “onFinishEditDialog” from the dialog after inputting the text.
This is the line that calls this function from the dialogfragment.
This is the activity class.
MainActivity.java
Please leave your valuable comments if you found this post useful.
You can download the complete source code for the above post from here.
Link to this post!
More Similar Posts
Using DialogFragments in Android – A Simple example.
How to listen to software keyboard done button in android?
How to hide and show a Fragment with animation in Android?…
How to create Swiping Windows in Android from Android 2.1…
How to place layouts one over another in android using…