No video

Fragment to Fragment Communication in Android Studio [Kotlin 2020]

  Рет қаралды 53,051

CodeWithMazn

CodeWithMazn

Күн бұрын

In this video we will learn how to send data between two fragments. Since two fragments should be modular, reusable components, and independent, the communication between two fragments should not be directly. Therefore, I will show you how to send data from one fragment to another fragment using Interface in Kotlin.
I hope you enjoy it and happy coding!!!
🔴 Subscribe for more educational tutorials on CodeWithMazn channel!
Follow me on Instagram
/ codewithmazn

Пікірлер: 43
@ganeshvaranletchumanan133
@ganeshvaranletchumanan133 3 жыл бұрын
For beginners like myself who are facing the problem whereby the "sendBtn" and "messageInput" is not recognised in the fragment kotlin file, please add the id 'kotlin-android-extensions' in your build gradle (app), under the plugins section.
@olhaangel4228
@olhaangel4228 3 жыл бұрын
It doesn`t work for me :( help
@ganeshvaranletchumanan133
@ganeshvaranletchumanan133 3 жыл бұрын
@@olhaangel4228 after adding the plugin make sure you sync your files.
@joshuavirina4287
@joshuavirina4287 2 жыл бұрын
@@ganeshvaranletchumanan133 i already add id kotlin but still work i already sync
@benstheweatherdog
@benstheweatherdog 2 жыл бұрын
Thank you so much my friend
@awandengcobo6208
@awandengcobo6208 2 жыл бұрын
Thank you very much, it worked for me to
@wasgibts5665
@wasgibts5665 3 жыл бұрын
Your hard work is very appreciated, you are the best out there, keep it up
@nanabananadraws1154
@nanabananadraws1154 3 жыл бұрын
Is there one where you pass a dynamic data from an activity to a fragment? I can't seem to find a way that works in kotlin and you're the only youtuber that I understand.
@CodeWithMazn
@CodeWithMazn 3 жыл бұрын
You can pass an object to a fragment. Your object can hold any type of data. I would also recommend you to check my navigation component series. I pretty much explain how to pass data using safe args. You can specify what type to pass from one fragment to another. I highly recommend navigation component!
@marioagrataboada4610
@marioagrataboada4610 2 жыл бұрын
Very clear bro!!! thank you so much
@BilalBerek-tl3tq
@BilalBerek-tl3tq Жыл бұрын
i have subscribed great work man
@Azil7136
@Azil7136 3 жыл бұрын
Pliss help 9:32 my send Btn error
@joshuavirina4287
@joshuavirina4287 2 жыл бұрын
You resolve this error?
@DuckDevAI
@DuckDevAI 2 жыл бұрын
you need to go to your build graddle and add PLUGIN 'kotlin-android-extensions' , NOT IMPLEMENTATION, so your puglins should look like these plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'kotlin-android-extensions' }
@user-fb1fs8by8e
@user-fb1fs8by8e 2 жыл бұрын
Please, explain, what is _arguments_ ? And what means _activity_ in FragmentA class ? I totally missunderstood that.
@Lin-rr5rs
@Lin-rr5rs 3 жыл бұрын
I'm also new to android. In your example, only takes care of sending data from frag A to B, what about if I also want to achieve sending data from B to A, takes care of both directions? Thanks
@m-j-y8289
@m-j-y8289 3 жыл бұрын
Very nice video! Could you also please make one about passing data from fragment to activity
@mohamed.elghazal1571
@mohamed.elghazal1571 3 жыл бұрын
Very good work
@waleefalrooh8
@waleefalrooh8 3 жыл бұрын
How can i do the transaction from a recyclerview button? .. pls if u have a blog on how to do it it will help me alot
@DuckDevAI
@DuckDevAI 2 жыл бұрын
For those who sendBtn is not being detected by the view. min 9:35 , here is the fix for it you need to go to your build graddle and add PLUGIN 'kotlin-android-extensions' , NOT IMPLEMENTATION, so your puglins should look like these plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'kotlin-android-extensions' }
@rajeev97
@rajeev97 3 жыл бұрын
Good Video! Just one suggestion.Aren't you supposed to check if the Host(Activity) is implementing the interface before casting it on Attach itself.The reason why it is not advisable to be done in onCreateView according to me is, it is called every time when you enter the fragment(in cases when it is replaced by other fragment & popped back by back press) but onAttach is called only once when it attached to the view hierarchy!
@CodeWithMazn
@CodeWithMazn 3 жыл бұрын
Thank you for your comment! I agree with you! My main attention was to show only how to pass data between two fragments. We can do a lot to make it better. I highly recommend you to watch my navigation component mini tutorial series!
@nm86nm
@nm86nm 3 жыл бұрын
How I can do that if I want to use ViewPager2?
@user-ck6oj3jc8s
@user-ck6oj3jc8s 11 ай бұрын
it is not setting the text on fragment. No error message as well
@gabrielfaria5421
@gabrielfaria5421 3 жыл бұрын
hey, very helpful video, i was wondering how I make the "transaction. replace(R.id.fragment,fragmentB)" in 8:21 when my fragmentB is an abstract class with parameters, i can't do the replace function with parameters
@fadzriangibran799
@fadzriangibran799 3 жыл бұрын
What if this is the case, fragment A in activity A will send data to fragment B in Activity B?
@srikanthgutti5056
@srikanthgutti5056 3 жыл бұрын
In Comminicator interface method , other than string can we pass object ? if Yes then how to do that?
@CodeWithMazn
@CodeWithMazn 3 жыл бұрын
Yes you can pass an object. Instead of passing a string, you can pass an object or array. I highly recommend you to watch my navigation component tutorial series! I pretty much explain how to pass data with saf args
@WlaDiSS
@WlaDiSS 3 жыл бұрын
Please, how could I pass data from second fragment to first fragment ?
@dreamer6228751
@dreamer6228751 3 жыл бұрын
Great video ☺️👌
@Attee_Q
@Attee_Q 2 жыл бұрын
Does this work with BottomNavigation?
@riteshsahu2102
@riteshsahu2102 3 жыл бұрын
Without findviewbyid how could u set onclicklistner
@AnuragKumar-lv3ul
@AnuragKumar-lv3ul 4 жыл бұрын
At 10:43 view.displayMessage.tostring() = displayMessage, showes me error, please help
@S_Karthik
@S_Karthik 3 жыл бұрын
i got the same, use your fragment layout xml text view ID.
@joshuavirina4287
@joshuavirina4287 2 жыл бұрын
@@S_Karthik how
@xD-saleem
@xD-saleem 3 жыл бұрын
Is this approach the best way to pass messages via fragements or intents?
@CodeWithMazn
@CodeWithMazn 3 жыл бұрын
I would say its a good way to pass data between fragments. If you want to take it to the next level, check my new tutorial series on navigation component. You can have a single activity approach app. Then, you can have multiple fragments. Passing data from one fragment to smother is really easy and safe. Navigation component uses safe args to pass data between fragments, which prevents you to get mismatch type errors and app crashes. I highly recommend navigation component!
@TheKidrock1988
@TheKidrock1988 3 жыл бұрын
view.sendBtn can't find this id ="sendBtn" help?
@sbf44777
@sbf44777 3 жыл бұрын
You need to add plugin id 'kotlin-android-extensions' in your build.gradle file and sync after this
@RaajKanchan
@RaajKanchan 2 жыл бұрын
@@sbf44777 Thank you for the help
@danielekpenyong5930
@danielekpenyong5930 2 жыл бұрын
what of the github repo
@blatezers5973
@blatezers5973 3 жыл бұрын
ViewModel ?
@mhee4832
@mhee4832 2 жыл бұрын
9:30 Line #29 'SendBtn' error. I already check fragment_a.xml that I already have android:id="@+id/sendBtn"
Dialog Fragment in Android [Kotlin 2020]
10:00
CodeWithMazn
Рет қаралды 37 М.
"Hack ANY Cell Phone" - Hacker Shows How Easy It Is To Hack Your Cell Phone
15:56
Magic or …? 😱 reveal video on profile 🫢
00:14
Andrey Grechka
Рет қаралды 51 МЛН
PEDRO PEDRO INSIDEOUT
00:10
MOOMOO STUDIO [무무 스튜디오]
Рет қаралды 24 МЛН
Yummy Lifehack 😋 @artur-boy
00:19
Andrey Grechka
Рет қаралды 4,5 МЛН
FRAGMENTS - Android Fundamentals
17:29
Philipp Lackner
Рет қаралды 329 М.
Android ViewBinding in 8 Minutes
8:59
Philipp Lackner
Рет қаралды 76 М.
RecyclerView in Android Studio [Kotlin 2020]
15:49
CodeWithMazn
Рет қаралды 58 М.
Bottom Navigation Bar in Android Studio [Kotlin 2020]
12:57
CodeWithMazn
Рет қаралды 45 М.
Dialog Fragment to Fragment
16:05
CodingWithMitch
Рет қаралды 49 М.
The Most Legendary Programmers Of All Time
11:49
Aaron Jack
Рет қаралды 555 М.
Preferences DataStore in 10min (SharedPreferences deprecated)
11:14
Philipp Lackner
Рет қаралды 74 М.
RecyclerView | Everything You Need to Know
25:07
Practical Coding
Рет қаралды 135 М.
Navigation Drawer and Bottom Navigation View in Android Studio | Kotlin
27:36