Coder Social home page Coder Social logo

Comments (2)

Darius82 avatar Darius82 commented on August 15, 2024

This is the approach I'd love to have. I'm having such a hard time implementing an onclicklistener to navigate to a "detail fragment". I don't want to use the Navigation component yet.

Could you give some more info? I'm new to android development and it's been tough for me to adapt to this new environment.

So, what I've understood is that I have to define an interface inside the adapter
interface iOnClickListener{ fun OnPlantClickedListener(view: View, plant: Plant) }

Then I implement that interface in the Fragment

override fun OnPlantClickedListener(view: View, plant: Plant) { //navigation stuff }

Points 3 and 4 I cannot understand very well.

I mean, in the list item XML, do I have to specify a variable just like the clickListener or the Plant? Wich one would it be?

Also, I don't get how to pass the OnPlantClickListener or how to create the setOnPlantClickedListener.

And I wonder what would I have to do with the clickListener function that is already in the adapter.

I will totally understand if you don't want to help me with this, I've been googling for days and although I have found some info on this subject I am not abe to implement it in "the sunflower project·.

from sunflower.

KoTius avatar KoTius commented on August 15, 2024

@Darius82 I believe it's late answer for you but still.
Point 3 is Databinding component. This is already implemented in list_item_plant.xml, we just change interface from VIew.OnClickListener with created by us OnPlantClickedListener, and then we change "onClick" in XML to call specified method.
Point 4 it when, in Fragment's onCreateView when we create PlantAdapter() we provide him either into constructor or setMethod instance of this OnPlantClickedListener (for simplify lets say its fragment itself "this").
PlanAdapter saves this object as a member variable and then, in ViewHolder.bind() method, we pass this member variable to xml binding.

from sunflower.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.