hello everyone! my name is oum saokosal. today, we will continue our lesson about androidrecyclerview. we will talk about event listener. you want to click on the first item you wantto go to another activity to display all the
Android intent, information about the item. so, this is my youtube channel. you can find good lessons about androids andsome other things. oum saokosal.
facebook page, kosalgeek. twitter and github. and in previous lesson, we used one of mylibrary to cnovert the json to arraylist in the github as well. so, the purpose of this video, it's like youhave this and then you click on that item and then you will show the whole data of theitem. impress you, you come to this video just forthe plus sign, i suggest you to go to youtube and you can just type android recyclerviewand my name. you're going to see this.
this is the english version and this is itskhmer version. i done a little bit similar so that you canfind the source code in the thing in part three, no impact five. just go down here and you will see the sourcecode here. you can continue from there. this is our previous lesson that we can clickon open. showed it at the item like that. now, we want to click on the item. so, it's very easy actually.
first, you want to know where you want toclick, right? so, you go to your adapter here. and then, you will see the binding here andyou want to click on the image, right? call it, image, iv, no, holder iv image url. no, no, no, sorry. it's just holder, ivimage url. this one, image thing and then, you want tostep on click listener. actually, it's not image url, it's just image. i confused myself.
so, i should rename that to image, not imageurl. here is the real image. so, i have the refractor. just delete that. just give image. okay, now, the image. you want to click on the image and then yousay this, no, new but not this and then control space. then, you will see the even here.
this is where you want to set the accent forthe clicking. you want to have toast. make like that. and you can use to context here. it's context. and click. so, let's run it. if you don't know and you don't understandthis, i think you should go back to the previous one.
because i just followed the two other, previousmaterial. i cannot explain it again. we're going to waste a lot of time for that. and in this video, we should just focus onthe event listener. so, now, let's see. see that? image clicked. so, you click on item one here. it's going to show the item one.
it's item two. okay, so how to deal with the specific item. actually it's very easy. because we got the product here already. & if you want to make sure, just refract tosomething like, selected product. it's better. now, it's selected. so, this is the product that you selected. and you want to show something.
let's say, it was product name. now, you want to declare it final becauseyou used in selected product inside that. and only first class. so, it should be final over here. so, i think it's running. not completed. wait a little bit. okay, it looks like it's going to run now. yes, see it again.
yes, new item. it's just the title here. let's go down a little bit. let's see the cat here. okay, now it's a cat. that is the item that you want, the product. you want to send this data to another page. another duty. so, let's create another activity here.
and you choose activity. okay, slowly. raising activity here. and rename it to detail activity. and the hierarchical is very important. you want to have the back button, so you choosethis when you click back, you can come back to the main page. and here, you want to have like, image, title,data. so, you have to look back in your database.
so, you can go back and what is the database? i got my database now, so let's see the wholething. that's good customer product for that. so, let' go back a little bit here to seecustomer here and connection. so, the database is customer as well. so, it's my customer here. so, product here. structure is just one image. you know, name.
so you want to have this as well. quantity, price. just go to here and go to content detail here. you want to have one image. imageview. drag and make sure that the arrow is exactly like me. like this and usually i go to code and thenadd some image there after default here. drawable pp. that is the image.
scale type, centercrop. so, the height 300 dp. it's too big and you can scale down yourself. and add some text here. just maybe, one is enough. maybe another one, down here. that looks good. just rename it. ivimage.
check it and just, it's fine. maybe the prize already happened. sorry for the noise. let's go back to the activity. so, you want to send the data from here. so, first you have to make sure that the classproduct has to implement serializable. without that, you cannot send the whole object. here, intent. you want to go from, new intent.
you want to have from context and go to intentand do to the class. that's good. in inputextra, put. just call product. this is the data you want to select. startactivity. so, now, you cannot start tv because thereis no, the product at the matter is not the activity. so, i think you can use another thing.
maybe, view but we had to get a view somewhere. where is it? i think over here. we can use holder. no, i think there is a trick here becauseyou want to send the data from one activity to another and here is not the activity. let's see. maybe we can just copy. so, now, view can be used anywhere here.
so, view. activity, no. let me see. which one? is it the layout? is it the�? let me check. i forgot it. okay, found in four.
put the context here. you know, the main activity that we got itfrom here. set it from outside or the context is theplace where you want to start the activity. then you can start it. so, this is the code that you want to some,send the data from this. like, even click on the image and then youput the whole object that we got from the selected here. and then we use the context here to startthe activity. and you go to the detail right here.
just call, check it a little bit like here,get intent, get serializable extra. which is the key? here is the key. and product null. it means that sometime you didn't send a datalike the product that you didn't send. or misspelled it like product with a p capitaland you'll see it with the wrong key. with small p like that, so guys have to becareful on that. so, we have to make sure that it's not now. then, we can get the data.
so, let's just call it text, this one is this. so, you can get the data, this product righthere. but we have to cast it as well before, justlike a general object, we have the product for that now. name. okay, let's see. maybe this one is good. there's some error here. let's see, what is the error?
calling start activity from outside. yeah, i forgot one thing here. so, we want to set this because we use contextoutside, so the error is not real error. i guess it's trying to tell you that justgo and you go code down there and set it. set flags something, just pass the code. but i think, yes something like this. it's going to work. get away. so, run again.
let's see, over here, cat and you see thewhole thing. it's a cat now and it's just full image beforetext. you get the data from the phone. and put it into the cell activity. imageview, ivimage. tvprice. findview. and it's wrong again. but this one must be textview.
you need picasso. so the code for picasso is here. it's helping. you just have to code here. and the context is this and the url is theproduct that you need the full url here because, you need to note the ip. holder is not the holder anymore. just the ivimage. and the text, tvtitle and product, just name.
just name the last one price. but the price is like, an integer and vowel,a number, i'm not sure about it. maybe you can just put dollar sign in frontof it. i think it's going to work. and it's all about that. let's wait a little bit. it's running now. okay, item number three is the cat. the title is cat and the price is five dollar.
so, that's all. now, you can reduce the, even click on theitem and then you can send the data from one of this to another and then you can receivethat and then put into the detail page and if you want to have a lot of data. like here, lot of image, i suggest you toput the scroll view because maybe this one is okay but when you rotate it, you're goingto have some problem. so, you can put the scroll or maybe just,i can do it for you. it's not a big deal. just cut this and then put the scroll viewand then here, match parent.
and the scroll view needs another layout andmatch parent. and put something over here and now you havea nice scroll view.
even though there are like size differentbut now you can see the opening here. you want to get rid of it, you can just doit in the activity here. just delete the old one, leave it or maybeyou want to move to somewhere. that's it for this video and we will see youin the next one.