Android Studio Custom Fragment Dialog

In this Android Studio article i want to show you How To Create Custom Fragment Dialog.

so  for good explanation you can watch the video for this article.

 

 

 

Also you can read more android development articles

1: Android Development Articles

 

 

 

Also you can check Python GUI Development Tutorials in the below link.

1: PyQt5 GUI Development Tutorials

2: TKinter GUI Development Tutorials

3: Pyside2 GUI Development Tutorials 

4: Kivy GUI Development Tutorials

5: wxPython GUI Development Tutorials 

 

 

 

 

1: First of all create a new project in your Android Studio, and choose Empty Activity

also iam using API 20 for this project.

2: So now open your activity_main.xml and wee need to add a Button with a Textview in

their like this . i have removed the text of the Textview because we are going to send data

from our Custom Fragment Dialog to the MainActivity.

 

 

 

 

 

3: OK after that you need to first create a class of CustomFragmentDialog, also you need

to open your layout folder for creating custom_layout.xml for your CustomFragmentDialog.

because we are going to inflate this custom_layout.xml from our CustomFragmentDialog class.

So this is our custom_layout.xml, and we need to add some widgets in our  layout, basically

we need a LinearLayout, a Textview,  Editext and two PushButton like this.

 

 

 

 

 

And now this is our CustomFragmentDialog.java class.

 

Our this class extends from DialogFragment,  also at the top of the class first we have created the object for our Button and EditText. and we have added the onCreateView method in our class , because when you want to inflate your fragment xml layout you need to add onCreateView life cycle. 

4: also in the MainActivity.java first we need to reference our button that we have added in activity_main.xml.

after that we need to setOnClickListener for our button, because we want to open our Custom Fragment Dialog from our main activity.

 

 

 

 

 

 

So now run the complete project and this will be the result

Android Studio Custom Fragment Dialog
Android Studio Custom Fragment Dialog

 

 

 

 

 

 

Also you can watch the complete video for this article

 

 

 

Video for sending data from Fragment Dialog to MainActivity.

Subscribe and Get Free Video Courses & Articles in your Email

 

Codeloop
Share via
Copy link
Powered by Social Snap
×