How to manage mupltiple constructors and destructors in the app?

So whoever creates this dog adapter will have to implement that and pass it in the constructor and we’ll save it in our instance here right see m click interface is equal to this now the person passes it what we do is whenever the the item is clicked the view is clicked we call that method by passing in the position now why do we need to pass position so we know exactly which dog was clicked so get adaptive position gives us that you can uncover these lines up next in main activity now you notice there’s an error here because a dog’s adapter constructor takes in three parameters now so you can uh wherever this like the code written you can uncomment those out

here i’ll put in this and what we’ll do is we’ll implement it or this is to do lemon yeah implement the click interface so basically this interface here that we just created is now let’s implement this in miniature.java so here to save time you can okay let me go slowly alt enter implement methods and implement on doubt click uh here within on.click so you have to basically write this code so here is what you’re going to do i’ll go really quickly on this one because we have covered this previously where do you want to go from you want to go from this where you want to go to details activity dot class so which is this one so when you click on on something it takes us to the screen so here we have the intent then uh intent dot put extra

we’ll give it the key of dog and the thing is we want to give it the click double line so we have the position so let us do m dogs position so again so this i’m going quickly on this one so any questions be sure to ask but trust me on this one this this will become very easy once you practice this right because no questions are coming in so maybe people are they find it too difficult but it isn’t it really isn’t so don’t worry about that

i’m always here to help you so be sure to ask your questions and now let us start our activity during the intent so we put the dog as an extra in the intent remember we explained all those the envelope then this is the post box that in the postman you know gives the we give the envelope to the postman it sends it cool now we have sent the dog let us receive the dog in our detail screen so in our detail screen all this code is pre-written for you so populate ui it you know takes it from m dog currently

dog is null but what we do is we take the intent that was passed to us and we extract it so you can just copy this or i won’t copy all for the sake of time basically we take the parcelable so whenever you want to pass in an object right here passing dog dog must have to implement parcelable so we did that first now here we have to get parcelable extra it’s like get the object and we get it here and 17. there were 19 to do’s so i’m missing two oh there were 17. so now if everything works correctly our app should work and so fingers crossed let’s see how this works and be sure to put your questions in so let’s see so we know a list works because it worked in the previous step so everything works if you click on it yeah everything works here too

what we’ll do is since we’ve completed this step we have covered i’ll give you a quick summary of what we’ve covered we’ll open it to questions and then if you don’t have questions i will give you a very brief summary of what you’ve done again so it’ll be i’m trying to cement all that you’ve learned at least to some extent to help all of us cool first things first we we took a dog object we implemented past level because we want to pass in the intent in our envelope we want to put this dog object so we have to if you want to put dog m dogs is a list of dogs right array of doubts so we took the dog we implemented possible and we did all this the the process right to implement it so we don’t have any errors then in our adapter

we created this interface called dog click interface it has this one abstract method abstract method method without implementation right you see there’s no no code here no code here next what we did was we created an you know a member variable of that interface we added it to the constructor then whenever the item view was clicked so in our dog view holder whenever the item view was clicked we call that interfaces method on.click which is this an interface so now what do we do we so our adapter will call that method but hey we haven’t really given any code to this method so how is it working well that comes to our second part which is in main activity.java which here what we did was we implemented that interface so again these are java concepts or basically this oop concepts object control programming concepts of interfaces so we over we implemented the interface so we have to override that method so on.

click we overload that method then we created an intent as always like as usual we created the envelope we put our letter in the envelope but earlier we used to pass like dog name dog bleed individually like i’ll show you the code in our week five app let me show you main activity java and adapter so this is the old code yeah you see here we passing the name breed likes dislikes image url separately but now what we did was in today’s app you see just one line of code well you have to put five letters in the envelope now we just put one letter in the envelope with the key dog how do we do that because of the past level so we can’t directly put dogs here because intense it works only with bite streams

so we have to convert the dog to a bite sweet and then put it here next to retrieve this information in details activity let me show you details activity previously you see it has to taken get intend dot get string extra five times as a programmer you always want to do everything efficiently so what m dog dot get name get greed you see earlier we had to create five fields i’m scrolling too much yeah here five separate variables and then equate it here so i hope this is like somewhat clear so this yes yes i will definitely repeat so uh in today’s app recyclerview you is absolutely so if you notice here in today’s app um in our uh here so in our details activity.

java we are retrieving a doll so basically we have got the envelope right your recipient has got the envelope now remove the letters out of it currently we’re just removing one letter which is very efficient so this one letter it encapsulates all the information like name of the dog breed of the dog likes the of the dog dislikes of the dog and image of the dog right because m dog earlier so let me do alt tab this is the app from week five here what we did was we have to extract each of these five letters in the envelope so in today’s app we just have one one letter in the envelope in last week’s app

We had five letters in the envelope and that’s why you have to do like string string string right the individual fields but now what we did was we did something clever which is we put all this this the fields in this one dog object right all these fields here and this dog object and then we extract it from our envelope the entire dog itself and how is that possible

because of a dog it implements parcelable so possible is for bite streams so these are some words which will get familiar with you don’t worry dot seven to the t so anyway uh dog um yep in intense whenever you want to passing objects you can’t pass on objects the work around around that or the work around to work around that is you convert objects using the passable interface to a byte stream and then you know don’t put extra you can pass in an actual object here and not just the primitives like you know ink double

the pseudo primitive you know like string um now it even takes in actual objects so you can put in the entire dog instead of last week where you had to put all these five fields separately right envelope.put letter in all the five letters individually this time we just put one letter that has all dog information well i hope i summarize that to a good extent so any questions will uh

i’ll cover those questions um and also after this session you can send me some questions either to either through linkedin i can and uh i’ll be happy to answer those so yeah yeah so uh no problem so uh what we’ll do is uh yep so this i hope this kind of helped in in some way the cheat sheet could help you in the future the slides uh you know you can refer the slides in the video by watching the video and uh yep that’s that’s it for for this week uh all of us we hope you learned something and you know okay like we hope this this helped you in some way and uh so see you in the next week where we’re going to do a back to back on wednesday and thursday of next week our capstone project so viewers are pretty excited

Leave a Comment