Thank you very much, I'm developing my app and I didn't know how I used dialogs within fragments, but you gave me a great help. I am Brazilian and here it is difficult to find good videos on android.
The reason why it wouldn't work with v4 fragment might be that for it to work you need to use getSupportFragmentManager() I think. And also, extend FragmentActivity.
Hi, when I click the button I have this error. java.lang.NullPointerException: Attempt to invoke virtual method 'void com.ola.ricardo.ola2.MainFragment.sendInput(java.lang.String)' on a null object reference How can I resolve this?
Hi Mitch. I was following this tutorial and i ended up having a recyclerview in the dialog fragment. I was able to do a toast on the recyclerview item click. But i am not able to close the dialog fragment along with that toast. I mean i click an option in the recyclerview through its adapter but i am not able close this dialog fragment along with this click, probably as i dont have a reference to the dialog fragment in the adapter of the recycler view. Can you please help me. I am still a beginner so please explain in terms of exact code to write. Thanks already for the beautiful and followable tutorials.
Thank god I found this video T_T.. Thanks bro, it helped, gonna sub and like this video. Many thanks again, you don't know how you had helped a needy guy
What if I want to send some value to the dialog from the MainFragment as well? Do I need to create an interface in the MainFragment and then let the DialogFragment implement it? Or is there a workaround of some kind? I don't want the Activity to be involved in this. (Although I know that's the best practice, event bus and all...)
every thing was working good when i used dialogs in Activities .....but now with Framents the getFragmentManager() method is not working .....can anybody help me to find a solution ??
getTargetFragment() is deprecated, how to replace this? edit I found the way (i only know how to use it in kotlin so maybe you can copy paste it and let android studio convert it to java) : in MainFragment //inside your open dialog clickListener var dialog = MyCustomDialog() dialog.show(parentFragmentManager, "MyCustomDialog") dialog.setFragmentResultListener("1"){ key, bundle -> if (key == "1"){ mInputDisplay.text = bundle.getString("1") } } in MyCustomDialog //inside m.ActionOk button val input: String = mInput.getText().toString() val bundle = Bundle() bundle.putString("1", input) setFragmentResult("1", bundle) dismiss() so no need to use onAttach and implement the interface, hope this helps!
Yes, its works, but i think i got better idea. In onAttach method insted mOnInputSelected = (onInputSelected) getTargetFragment(); use mOnInputSelected = (mOnInputSelected) getParentFragmentManager().findFragmentByTag("TAG");//IMPORTANT! TAG is that you use when you cal your fragment in FragmentTransaction.replace () and when you create a dialog, insted dialog.setTargetFragment(MainFragment.this, 1); use getParentFragmentManager().setFragmentResultListener(1, MainFragment.this, new FragmentResultListener() { @Override public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) { } }); dialog.show(getParentFragmentManager(),"MyCustomDialog") And it works exacly like when you use dialogs in Activity
Okay video, but it is best to try and keep software as loosely couple as possible - this video promotes a direct relationship between the dialog and the fragment for changing the textview. It would be better to use an interface as a callback to change the textViews. The fragment implements the interface, the fragment passes a reference of itself through an init() method when creating the interface.
Hello my friend, great video, but the dialogfragment are callback from the activitymain but not from de an fragment, have you and example or any link where show it ? Call back an dialog fragmet from the fragment (not activity main). Thank in advance. Regards.
Hey Berna, Could you elaborate? I might have an issue related to what your saying. I get a " declared fragment fragmentName that does not belong to this fragmentManager" something to do with the setTargetFragment
Hey Mitch, I'm an iOS dev trying to master Android. I have a little problem I'd like you to assist me with. I want to calc the size(width and height) of a String. Folks on Stackoverflow say i should use Paint() but it couldn't give me accurate results. Do you have a more accurate way i can calculate the size of a String?
I'm thinking of using this method to be able to change the link of a videoview.. But I do not know how to use this method to change a configuration of the class example: the person clicks the button to open the AlertDialog and has the edittext asking for the stream link of the video that will be played in Videoview, the person puts the link and automatically "Change" The link in MainActivity. Class (click in show more) I made a post on Stackoverflow.. Please help me! stackoverflow.com/questions/49435976/change-link-of-videoview