Fragment to Fragment Communication in Android Studio [Kotlin 2020]

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ต.ค. 2024

ความคิดเห็น • 44

  • @wasgibts5665
    @wasgibts5665 3 ปีที่แล้ว +1

    Your hard work is very appreciated, you are the best out there, keep it up

  • @ganeshvaranletchumanan133
    @ganeshvaranletchumanan133 3 ปีที่แล้ว +9

    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

  • @nanabananadraws1154
    @nanabananadraws1154 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +4

      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!

  • @BilalBerek-tl3tq
    @BilalBerek-tl3tq ปีที่แล้ว

    i have subscribed great work man

  • @TheGuy-h6c
    @TheGuy-h6c 2 ปีที่แล้ว +1

    Please, explain, what is _arguments_ ? And what means _activity_ in FragmentA class ? I totally missunderstood that.

  • @Lin-rr5rs
    @Lin-rr5rs 3 ปีที่แล้ว +1

    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

  • @marioagrataboada4610
    @marioagrataboada4610 2 ปีที่แล้ว

    Very clear bro!!! thank you so much

  • @chrakesh5181
    @chrakesh5181 หลายเดือนก่อน

    Nice tutorial sir.
    In the same way, How to send data from fragment to activity?

  • @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

  • @nm86nm
    @nm86nm 3 ปีที่แล้ว +1

    How I can do that if I want to use ViewPager2?

  • @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'
    }

  • @Attee_Q
    @Attee_Q 2 ปีที่แล้ว

    Does this work with BottomNavigation?

  • @AppHouse-m6r
    @AppHouse-m6r ปีที่แล้ว

    it is not setting the text on fragment. No error message as well

  • @mohamed.elghazal1571
    @mohamed.elghazal1571 3 ปีที่แล้ว

    Very good work

  • @m-j-y8289
    @m-j-y8289 3 ปีที่แล้ว

    Very nice video! Could you also please make one about passing data from fragment to activity

  • @srikanthgutti5056
    @srikanthgutti5056 3 ปีที่แล้ว +1

    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

  • @useptampan123
    @useptampan123 3 ปีที่แล้ว

    What if this is the case, fragment A in activity A will send data to fragment B in Activity B?

  • @Azil7136
    @Azil7136 3 ปีที่แล้ว +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'
      }

  • @WlaDiSS
    @WlaDiSS 3 ปีที่แล้ว

    Please, how could I pass data from second fragment to first fragment ?

  • @riteshsahu2102
    @riteshsahu2102 3 ปีที่แล้ว

    Without findviewbyid how could u set onclicklistner

  • @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 ปีที่แล้ว +2

      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!

  • @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

  • @AnuragKumar-lv3ul
    @AnuragKumar-lv3ul 4 ปีที่แล้ว +1

    At 10:43 view.displayMessage.tostring() = displayMessage, showes me error, please help

    • @S_Karthik
      @S_Karthik 4 ปีที่แล้ว +1

      i got the same, use your fragment layout xml text view ID.

    • @joshuavirina4287
      @joshuavirina4287 2 ปีที่แล้ว

      @@S_Karthik how

  • @dreamer6228751
    @dreamer6228751 4 ปีที่แล้ว

    Great video ☺️👌

  • @xD-saleem
    @xD-saleem 3 ปีที่แล้ว

    Is this approach the best way to pass messages via fragements or intents?

    • @CodeWithMazn
      @CodeWithMazn  3 ปีที่แล้ว +2

      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 ปีที่แล้ว +1

    view.sendBtn can't find this id ="sendBtn" help?

    • @sbf44777
      @sbf44777 3 ปีที่แล้ว +1

      You need to add plugin id 'kotlin-android-extensions' in your build.gradle file and sync after this

    • @RaajKanchan
      @RaajKanchan 3 ปีที่แล้ว

      @@sbf44777 Thank you for the help

  • @danielekpenyong5930
    @danielekpenyong5930 3 ปีที่แล้ว

    what of the github repo

  • @mhee4832
    @mhee4832 2 ปีที่แล้ว

    9:30 Line #29
    'SendBtn' error. I already check fragment_a.xml that I already have android:id="@+id/sendBtn"

  • @blatezers5973
    @blatezers5973 3 ปีที่แล้ว

    ViewModel ?