Tuesday 28 November 2017

Best Way to Create Android Database App in 30 Minutes

Hello everyone my name is Oum Saokosal.Today I will teach you best way to create Android Database App in 30 minutes.OK in this video you will learn Navigation Drawer RecyclerView, Android Volley, PHP MySQLI know it sounds a lot to you but if you want more detail you can find more videos on mychannel: Oum Saokosal my Facebook page: KosalGeek, Twitter: @okosal, and some source code inlibrary at github.com kosalgeek as well.So for this requirements, you have to have the Android Studio the latest one GenyMotionfor the Emulator XAMPP for PHP and Sublime Text.OK let' s go the project OK let' s open up the Android Studio.I use Android Studio 2.1.2 and then let' s call it AndroidDBApp1 and you choose the versionfor Android 4.0 that' s fine, you choose the Android Navigation Drawer because we wantto use that and just leave it like this.OK it is finished now so let' s run it because you wanna test it.OK it works now.So this is the Navigation Drawer, that’s it.OK so we want to make maybe a fragment on this one so I want to quick change a littlebit the menu so you go to menu here this one so I just delete all of this so I don' t needit OK and maybe just group like this.We just give it two option you know like this one for the you know like let' s say our Newsbecause maybe you want to have a News and then maybe product okay so give the item nameso usually I give the name like menu, menuNews, menuProduct OK.And then this one you want to change to something else but you if you don' t just delete it sojust wanna make quick change that' s it.And then you go to Java here and go down.

This one is a default you know like a quote like a generated for you so just change tomenu for that and delete all the rest here but don' t delete this part, this here is well,this one is very important and then you want to have a fragment so right-click on this,go to Fragment here and then choose the blank one and then uncheck this because we don' tneed it and just give it like NewsFragment OK and if you want for more detail about thisI have a good video on my YouTube channel about the Navigation Drawer.Please check it out.But for this purpose I just make a simple one okay and make sure that you import thefragment the right one you go to import here.If you see something like this OK it works but it has some problem when you use it inthe future so make sure you use the support version 4.0 OK so here you can use the RecyclerViewinside the Fragment OK so before anything you want to test it so you go to present therest in layout here in the FragmentNews OK just go here and then you know like you wantto test it, just grab maybe a clock OK like this.If you want to change to LinearLayout, you go LinearLayout OK something like that, that' sfine and if you wanna drag again OK doesn' t worry, it doesn' t matter and then maybe yourun it.Oh I forgot you have to call the fragment here of course we didn' t call it yeah so wego to MainActivity here and over here you just call the NewsFragment and you just callNewsFragment with a smaller case you know and then NewsFragment like this, that' s it.One more thing that you have to understand that fragment is a part of the Activity soyou have to know that where you want this fragment to go to so actually you will putit into the content_main here so you have to give like the name to the Relative hereso if you just delete it inside the content main and you have to give a name to the RelativeLayouthere.Well actually it' s ID not name, ID like this and then we' ll find like that and then maybeI call it MainLayout OK and this is the place that you want to put the fragment into allso you go back to MainActivity here and then you call FragmentManager and let' s call itManager, must be inside.OK and then get support of fragment manager here like that so now what we can do is manager.begintransactionand then you need to replace so we want to replace the fragment here and into the yeahcontent_main so remember that so R.layout.main wait no no, id.MainLayout and then newsFragment here okay and you want to put the text, it is OK.

 if you don' t that' sfine OK so if you want to have a Default Activity just copy this and pass it to the onCreatehere, down here that' s fine you have to call commit() at the end so it doesn' t run becauseyou just call the replace and then you have committed so run again OK now you see theclock it means that the activities, you know like take the fragment and put inside thatand this isn' t you and it' s clock here OK now you want to put the RecyclerView insidenewsFragment here and the fragment is called in like that.So you need some library so you have to Google and type Android RecyclerView and you go tohere and maybe this one too.So in this blog Google give you a very good you know example there so if you want to justgrab the code here, great, like that, you need a card like this OK so but before anythingyou have to put the dependency here but you have this plus sign you have to put the youknow the the latest one.So you go to here or maybe around it' s OK and then you Ctr+F and you find RecyclerViewso this is the dependency for RecyclerView so grab the code like this and then you goto Android and you go to gradle the second one, not the first one and you say compilethen paste like it and you need another one cardView so cardView is the like companionof the RecyclerView.So grab the code and compile again great so see now OK.It has some problem because my you know like I compile it with the version 23 now I use24 I think I have to change it to 23 maybe something this is fine.I have to do the sync again the reason that you got some error because I used the version4.0 remember when I create a project I used android 4 and this one is you know like thelatest updates so it' s gonna go to 24 and I used 23 so it' s fine just you know downgradelittle bit and if you want to use, you know, the latest one.But you have to change it properly but just go like quick quick now so it' s done and thengo back to here and ready for the RecyclerView so here copy and you go to layout so you goto fragment_news OK this one you don' t Analog clock whatever just this one and lets changeto rv and this one is news OK so you know like that it' s match parent so it' s gonnamatch the whole screen.This is for RecyclerView but then you need a cardView right click new and choose XMLand Layout here so I will call new_card_view OK like this and this and bring it to maybethat is fine maybe let you play out whatever, LinearLayout is fine and then you know likeI want to have one image and like two text or maybe two image whatever but let' s tryit so one image from the left and one at the right you know 2 image so let me try OK soI will create an inner layout called LinearLayout and this one is going to be this is match_parentbut I give it yeah match parent first and this one match parent first and inside hereI will have  image view and this one is going to be wrap content OKAnd should be there is a name here let it call left may be ivLeftImage and image scaleTypeis going to be centerCrop and maybe

 I don' t have a source and they want to use from Androidmaybe you want to have one image, let' s go grab an imagehere Angkor you know Angkor, it' s from my country here and we need to fill this spaceand no capital letter just only smaller case like that so you can have drawable and thenAngkor OK let' s see OK it' s gonna use the whole screen but then height I' m maybe justgive a 300dp like this OK so this one maybe 300dp here, cardView and outside here I needa CardView so grab the CardView somewhere yeah usually I put the CardView in the outernot inside like this and then CardView like this OK it complain because you don' t havethe name space here, pass it like this.Now you have all the point you want and this one window, yes.But the width of CardView is 200 it' s very small so I have to put it like match_screen,match_parent and this one is gonna be 300 so this one I put match_parents, it was 300now and this one I don' t look at the 14:39 300 again so it' s gonna be like this so Iwant to have two one from the left and one from the right so this one going to put theorientation horizontal OK and this one you have to put layout_weight this one and .5mean 50-percent you cannot put 50%, you can put 5 like that and this one is gonna be toleft and this one right OK and lets run again usually see something like that just pressOK.Now it' s done OK gravity center doesn' t matter OK and corner is 4 yeah maybe I just haveimage only, if you want some text it' s fine maybe just put the text below here OK butnow just make it quick quick.OK so you want to get the data from the database so you need Android Volley here so go backagain Android Volley OK so first you need you know like gradle you need to go to thisone, second one just like that you know like serial but the third one you going to grabthe code OK not this one you' re gonna grab this one and gradle again and sync it herelike that you know sync' s done so you need the you know like a class for MySingeltonit' s a code that prevent the calling, you know, like you' re gonna have to duplicate follow and MySingel ton is just like after when you create many object from a class sothis is the one going to protect you know only one instant an object creates from a class and this one we need to support version 4 here again, that' s fine.I know this sounds little bit difficult for you but if you wanna you know like a completecourse you go to my YouTube channel and now it' s done My Singelton and you go to the Newsfragmenthere you need it to call for this one My Singleton and get instant and then this so one problemnow you need this from outside so you can get the context from here context container.getcontext()here so this one is context and then you can add the request here OK so you need a stringRequestOK and StringRequest new StringRequest so this is calling to the network.so first you need like a method and this I go grab a data from the database so you startgetData OK and you want both data you use whole OK grab a data and you need URL hereso it' s URL so you will use the local one so you' re going to be 10.3.2.0 you have a18:50  like that but make sure you have to run this one as well.OK so I will make a project and gonna call it like examplenews and the fall is goingto be index PHP and this one say new no you' re going to be messy here so like this firstURL and this one and comma and another new below here so you have four this one is gonnagrab the data back when there is no error and when there is an error you get the errorfrom the error listener here OK so you need one more thing you have to go to Android manifesthere and you have to ask for permission this one' s gonna need internet like this rightOK now you can all StringRequest and put down below here so now you can call through thenetwork OK and this represents your local-host if you use a real server just put the youknow like this in Google just Google and put your URL OK but this one is going to be forthe local host and examplenews so I have to go here to them and create new folder.For Mac it' s going to be 20:27 and then rename it examplenews one more time.And then we will create a more like PHP index and you need sublime Text here so make sureyou did it all of this because you need only PHP and this one and you will send a dataso you just grab a data actually so you need a connection but maybe it' s better to createa make them outside, may be copy and paste like that, connection so you will need a serverand the server is local host and user is root and pass is blank and db so you will needa db database name so just call examplenews and then you will need like mysqlite connectand then server and user and pass and db and this one maybe you can call comm with a doublem here so if comm error may be just call the error OK and then call die so just call ErrorDB OK that' s all.And then we will get the connection here in to the index so you can include maybe includeonce and connection PHP

 OK so you wanna get all the database you know, like now you don' thave database so you go again localhost, my database is not running so let’s start itOK.So once again so you go to PHP myadmin, create a database, new database examplenews, usethe collation for the UTF-8 general CI this one great and just calling news maybe that' s4, it' s fine plus one ID and then we' re gonna be auto increment this one primary key andit' s called title and type varchar maybe 250 like this title an Image 1, this one justyou know Image URL and then maybe 250 that' s fine OK save.Now you can insert simple data here so like test image 1 and this one I call image1.sqland this one Image 2 then this one test image 2 and this one is gonna be 3, this is gonnabe 4 OK good, Now you have all the data here so you wanna get the data from the databasehere OK so mysql_query OK now you got the data okay and remember I' m using the sublimetext if you use notepad++ you will have some problem with the code here OK now you canget a data and then you want to put it into the Android here.So before anything you want to test here so this is the right spot in the data so justuse log like there may be just put name of the Fragment like that and this is the responseOK you open up the Android Monitor here and you like filter by a new fragment you cansee now the data is like this.If you see something in front of this like you know like some symbol that means thatyou have some error so you have to change to sublime text OK.Now the data is done and you want to convert this the... you know like the JSon onto thearraylist so you have to go to my github KosalGeek this one and then you go to KGJsonConvertorOK and then you have to grab the code and if you want to donate some money you can donatehere okay it' s free to use.So first you need the GSon so go here you can download the Gson here OK and then goback and then this one here to download my project or click download OK and zip it andcopy this one and go back and click here on the27:04 here and go to project on the apps- libs and right-click and pass it.Yes and another one, this one pass this and just you know like this and Add as library,you want to add this to the library that' s why right click on this so it will take sometime and now it' s completed go back to you know Android here OK so first you need tocreate a class that represent a data from the database so let’s call news as welland then you will have public integer ID, make sure that the name must match to thefield of database here ID title Image OK okay you cannot rename to anything andthis one String title and you have to use public as well and String Image 1 public StringImage 2.OK And then is the main Serializable here you want to get the response and then thecode convert to arraylist, it' s in my material here just grab the code you know like thisand then the response now is gonna be over here and the class is news OK now you havethe arraylist so you wanna put the arraylist into the RecyclerView the last part of thematerial, RecyclerView and rv and just call news OK so this one you need to use this soI go remain it to view so this one is going to be View like this.OK now you can just use view like this and find View by ID so now I can the rv yeah andwe have to be pass it okay now rvnews and you want you know like the setLayout usuallyyou use the linear layout.context and the context here must be final OK so now we have to set the hasFixed as trueand lastly you want to set the adapter the most important part here, so you need to createAdapter outside so I will call NewsAdapter OK so right click and create a class callNewsAdapter and then you have to extend RecyclerView Adapter and then inside that you will havethe you know like a View holder so RecyclerView, View Holder and then you have to implementthis so in the main method three method yeah.So here we need to call NewsAdapter and then NewsAdapter like that, NewsAdapter, so you want to pass the you know the arraylist into this one so you will create the contractorfor that.Hello everyone my name is Oum Saokosal. Today I will teach you best way to create AndroidDatabase App in 30 minutes. OK in this video you will learn Navigation Drawer RecyclerView,Android Volley, PHP MySQL I know it sounds a lot to you but if you want more detail youcan find more videos on my channel: Oum Saokosal my Facebook page: KosalGeek, Twitter: @okosal,and some source code in library at github.com kosalgeek as well.So for this requirements, you have to have the Android Studio the latest one GenyMotionfor the Emulator XAMPP for PHP and Sublime Text.

OK let' s go the project OK let' s openup the Android Studio. I use Android Studio 2.1.2 and then let' s call it AndroidDBApp1and you choose the version for Android 4.0 that' s fine, you choose the Android NavigationDrawer because we want to use that and just leave it like this. OK it is finished nowso let' s run it because you wanna test it. OK it works now. So this is the NavigationDrawer, that’s it.OK so we want to make maybe a fragment on this one so I want to quick change a littlebit the menu so you go to menu here this one so I just delete all of this so I don' t needit OK and maybe just group like this. We just give it two option you know like this onefor the you know like let' s say our News because maybe you want to have a News and then maybeproduct okay so give the item name so usually I give the name like menu, menuNews, menuProductOK.And then this one you want to change to something else but you if you don' t just delete it sojust wanna make quick change that' s it. And then you go to Java here and go down. Thisone is a default you know like a quote like a generated for you so just change to menufor that and delete all the rest here but don' t delete this part, this here is well,this one is very important and then you want to have a fragment so right-click on this,go to Fragment here and then choose the blank one and then uncheck this because we don' tneed it and just give it like NewsFragment OK and if you want for more detail about thisI have a good video on my YouTube channel about the Navigation Drawer. Please checkit out.But for this purpose I just make a simple one okay and make sure that you import thefragment the right one you go to import here. If you see something like this OK it worksbut it has some problem when you use it in the future so make sure you use the supportversion 4.0 OK so here you can use the RecyclerView inside the Fragment OK so before anythingyou want to test it so you go to present the rest in layout here in the FragmentNews OKjust go here and then you know like you want to test it, just grab maybe a clock OK likethis.If you want to change to LinearLayout, you go LinearLayout OK something like that, that' sfine and if you wanna drag again OK doesn' t worry, it doesn' t matter and then maybe yourun it.

 Oh I forgot you have to call the fragment here of course we didn' t call it yeah so wego to MainActivity here and over here you just call the NewsFragment and you just callNewsFragment with a smaller case you know and then NewsFragment like this, that' s it.One more thing that you have to understand that fragment is a part of the Activity soyou have to know that where you want this fragment to go to so actually you will putit into the content_main here so you have to give like the name to the Relative hereso if you just delete it inside the content main and you have to give a name to the RelativeLayouthere. Well actually it' s ID not name, ID like this and then we' ll find like that and thenmaybe I call it MainLayout OK and this is the place that you want to put the fragmentinto all so you go back to MainActivity here and then you call FragmentManager and let' scall it Manager, must be inside.OK and then get support of fragment manager here like that so now what we can do is manager.begintransactionand then you need to replace so we want to replace the fragment here and into the yeahcontent_main so remember that so R.layout.main wait no no, id.MainLayout and then newsFragmenthere okay and you want to put the text, it is OK. if you don' t that' s fine OK so if youwant to have a Default Activity just copy this and pass it to the onCreate here, downhere that' s fine you have to call commit() at the end so it doesn' t run because you justcall the replace and then you have committed so run again OK now you see the clock it meansthat the activities, you know like take the fragment and put inside that and this isn' tyou and it' s clock here OK now you want to put the RecyclerView inside newsFragment hereand the fragment is called in like that.So you need some library so you have to Google and type Android RecyclerView and you go tohere and maybe this one too. So in this blog Google give you a very good you know examplethere so if you want to just grab the code here, great, like that, you need a card likethis OK so but before anything you have to put the dependency here but you have thisplus sign you have to put the you know the the latest one. So you go to here or maybearound it' s OK and then you Ctr+F and you find RecyclerView so this is the dependencyfor RecyclerView so grab the code like this and then you go to Android and you go to gradlethe second one, not the first one and you say compile then paste like it and you needanother one cardView so cardView is the like companion of the RecyclerView.

So grab the code and compile again great so see now OK. It has some problem because myyou know like I compile it with the version 23 now I use 24 I think I have to change itto 23 maybe something this is fine. I have to do the sync again the reason that you gotsome error because I used the version 4.0 remember when I create a project I used android4 and this one is you know like the latest updates so it' s gonna go to 24 and I used23 so it' s fine just you know downgrade little bit and if you want to use, you know, thelatest one. But you have to change it properly but just go like quick quick now so it' s doneand then go back to here and ready for the RecyclerView so here copy and you go to layoutso you go to fragment_news OK this one you don' t Analog clock whatever just this oneand lets change to rv and this one is news OK so you know like that it' s match parentso it' s gonna match the whole screen.This is for RecyclerView but then you need a cardView right click new and choose XMLand Layout here so I will call new_card_view OK like this and this and bring it to maybethat is fine maybe let you play out whatever, LinearLayout is fine and then you know likeI want to have one image and like two text or maybe two image whatever but let' s tryit so one image from the left and one at the right you know 2 image so let me try OK soI will create an inner layout called LinearLayout and this one is going to be this is match_parentbut I give it yeah match parent first and this one match parent first and inside hereI will have  image view and this one is going to be wrap content OKAnd should be there is a name here let it call left may be ivLeftImage and image scaleTypeis going to be centerCrop and maybe I don' t have a source and they want to use from Androidmaybe you want to have one image, let' s go grab an image here Angkor you know Angkor,it' s from my country here and we need to fill this space and no capital letter just onlysmaller case like that so you can have drawable and then Angkor OK let' s see OK it' s gonnause the whole screen but then height I' m maybe just give a 300dp like this OK so this onemaybe 300dp here, cardView and outside here I need a CardView so grab the CardView somewhereyeah usually I put the CardView in the outer not inside like this and then CardView likethis OK it complain because you don' t have the name space here, pass it like this.Now you have all the point you want and this one window, yes. But the width of CardViewis 200 it' s very small so I have to put it like match_screen, match_parent and this oneis gonna be 300 so this one I put match_parents, it was 300 now and this one I don' t look atthe 14:39 300 again so it' s gonna be like this so I want to have two one from the leftand one from the right so this one going to put the orientation horizontal OK and thisone you have to put layout_weight this one and .5 mean 50-percent you cannot put 50%,you can put 5 like that and this one is gonna be to left and this one right OK and letsrun again usually see something like that just press OK. Now it' s done OK gravity centerdoesn' t matter OK and corner is 4 yeah maybe I just have image only, if you want some textit' s fine maybe just put the text below here OK but now just make it quick quick.OK so you want to get the data from the database so you need Android Volley here so go backagain Android Volley OK so first you need you know like gradle you need to go to thisone, second one just like that you know like serial but the third one you going to grabthe code OK not this one you' re gonna grab this one and gradle again and sync it herelike that you know sync' s done so you need the you know like a class for MySingeltonit' s a code that prevent the calling, you know, like you' re gonna have to duplicatefollow and MySingelton is just like after when you create many object from a class sothis is the one going to protect you know only one instant an object creates from aclass and this one we need to support version 4 here again, that' s fine. I know this soundslittle bit difficult for you but if you wanna you know like a complete course you go tomy YouTube channel and now it' s done MySingelton and you go to the Newsfragment here you needit to call for this one MySingelton and get instant and then this so one problem now youneed this from outside so you can get the context from here context container.getcontext()here so this one is context and then you can add the request here OK so you need a stringRequestOK and StringRequest new StringRequest so this is calling to the network. so first youneed like a method and this I go grab a data from the database so you start getData OKand you want both data you use whole OK grab a data and you need URL here so it' s URL soyou will use the local one so you' re going to be 10.3.2.0 you have a 18:50  like thatbut make sure you have to run this one as well.OK so I will make a project and gonna call it like examplenews and the fall is goingto be index PHP and this one say new no you' re going to be messy here so like this firstURL and this one and comma and another new below here so you have four this one is gonnagrab the data back when there is no error and when there is an error you get the errorfrom the error listener here OK so you need one more thing you have to go to Android manifesthere and you have to ask for permission this one' s gonna need internet like this rightOK now you can all StringRequest and put down below here so now you can call through thenetwork OK and this represents your local-host if you use a real server just put the youknow like this in Google just Google and put your URL OK but this one is going to be forthe local host and examplenews so I have to go here to them and create new folder. ForMac it' s going to be 20:27 and then rename it examplenews one more time.And then we will create a more like PHP index and you need sublime Text here so make sureyou did it all of this because you need only PHP and this one and you will send a dataso you just grab a data actually so you need a connection but maybe it' s better to createa make them outside, may be copy and paste like that, connection so you will need a serverand the server is local host and user is root and pass is blank and db so you will needa db database name so just call examplenews and then you will need like mysqlite connectand then server and user and pass and db and this one maybe you can call comm with a doublem here so if comm error may be just call the error OK and then call die so just call ErrorDB OK that' s all.

And then we will get the connection here in to the index so you caninclude maybe include once and connection PHP OK so you wanna get all the database youknow, like now you don' t have database so you go again localhost, my database is notrunning so let’s start it OK.So once again so you go to PHP myadmin, create a database, new database examplenews, usethe collation for the UTF-8 general CI this one great and just calling news maybe that' s4, it' s fine plus one ID and then we' re gonna be auto increment this one primary key andit' s called title and type varchar maybe 250 like this title an Image 1, this one justyou know Image URL and then maybe 250 that' s fine OK save. Now you can insert simple datahere so like test image 1 and this one I call image1.sql and this one Image 2 then thisone test image 2 and this one is gonna be 3, this is gonna be 4 OK good, Now you haveall the data here so you wanna get the data from the database here OK so mysql_query OKnow you got the data okay and remember I' m using the sublime text if you use notepad++you will have some problem with the code here OK now you can get a data and then you wantto put it into the Android here.So before anything you want to test here so this is the right spot in the data so justuse log like there may be just put name of the Fragment like that and this is the responseOK you open up the Android Monitor here and you like filter by a new fragment you cansee now the data is like this. If you see something in front of this like you know likesome symbol that means that you have some error so you have to change to sublime textOK.Now the data is done and you want to convert this the... you know like the JSon onto thearraylist so you have to go to my github KosalGeek this one and then you go to KGJsonConvertorOK and then you have to grab the code and if you want to donate some money you can donatehere okay it' s free to use. So first you need the GSon so go here you can download the Gsonhere OK and then go back and then this one here to download my project or click downloadOK and zip it and copy this one and go back and click here on the27:04 here and go toproject on the apps - libs and right-click and pass it. Yes and another one, this onepass this and just you know like this and Add as library, you want to add this to thelibrary that' s why right click on this so it will take some time and now it' s completedgo back to you know Android here OK so first you need to create a class that representa data from the database so let’s call news as well and then you will have public integerID, make sure that the name must match to the field of database here ID title Image1 OK okay you cannot rename to anything and this one String title and you have touse public as well and String Image 1 public String Image 2.OK And then is the main Serializable here you want to get the response and then thecode convert to arraylist, it' s in my material here just grab the code you know like thisand then the response now is gonna be over here and the class is news OK now you havethe arraylist so you wanna put the arraylist into the RecyclerView the last part of thematerial, RecyclerView and rv and just call news OK so this one you need to use this soI go remain it to view so this one is going to be View like this.OK now you can just use view like this and find View by ID so now I can the rv yeah andwe have to be pass it okay now rvnews and you want you know like the setLayout usuallyyou use the linear layout. context and the context here must be final OK so now we haveto set the hasFixed as true and lastly you want to set the adapter the most importantpart here, so you need to create Adapter outside so I will call NewsAdapter OK so right clickand create a class call NewsAdapter and then you have to extend RecyclerView Adapter andthen inside that you will have the you know like a View holder so RecyclerView, View Holderand then you have to implement this so in the main method three method yeah. So herewe need to call NewsAdapter and then NewsAdapter like that, NewsAdapter, so you want to passthe you know the arraylist into this one so you will create the contractor for that.Public news adapter and then you want to put the arraylist of news so it' s just newlist like this and then this, maybe you wanna put the context as well, context inside here,newsList no and this one to, and this one newsList and make sure that the return mustnot be zero, because zero means that no data so you will say like if newsList not nullthen you will return the newsList.size() OK and otherwise you will return zero OK.OK now you wanna pass it over here at the context and the userList not new list it' snewsList OK so first you have to create this one but you have to create an internal ViewHolderso you have to call public static NewsVH public class and then extends RecyclerView ViewHolderand then you have to implement a contractor like this and you have to check the cardViewthis one, so where is your cardView over here so you have image left and right, Right!So we need only this thing. The title we don' t have that so it doesn' t matter, so this onecardView and we would have a name for cardView yeah call it news Card and then we got to imageViewimage 1 and Image 2 so this one newsCard, CardView, this one 34:59 first here and you' llcall itemView find view by Id and newsCard and this one is imageView so I have to renameit like that as well OK now we have to create the ViewHolder so LayoutInflater and LayoutInflaterfrom parent.getContext() here and View view inflater inflate so we inflate the resourcehere so R.layout.newsCard OK so now we inflate that and then we put recall the news viewholder here so newsVH here so newsVH and then the data will come through this onBindView.So we get the data you know like release that like Array List the selected.

 Data so it' s gonnabe selected news and we' re gonna have the new list and then get from which position,this position will go to this one and then we wanna display an image so we need anotherlibrary so we will need Picasso this one, very simple.I usually use this one OK Picasso this one image and a URL so of course we need the dependencyas well just grab the gradle here OK so now the Picasso is OK but URL is not we need theimage so the image, the URL is the String , we can get an image from the selected News.Remember selectedNews is the arraylist so copy all of this image and we go to example,example news here and right click you know folder, gonna call image and pass it and thisone is image 1 but it' s PNG so I have to change the database a little bit, database, PNG,just rename all of this to PNG because the image is PNG so now the URL is in our databaseso I' m gonna put the real URL 38:05 localhost, this one is fine example news and the folderis image OK. Now it' s done now this one placeholder so I will just Android. Now the ImageView,ImageView is data from the View holder, this one usually I use the instance of holder instance of newsVH OK then I will convert to newsVH like that and this one is in the inside, and this one now put into the image left and lastly this one URL. So let me take it inside 1,2, this one 1, 2 this one right! OK. Oh I forgot so I just put ones in all, now let’s change one to two, this one previously it' s number 1 now it' s number 2, so let’s see OK now it' s running OK you can rotate it.OK that' s it for this video I hope you like it and don' t forget to subscribe my channel and give me a thumb up. Share to your friends on Facebook and twitter if you have any problem or question, Please Comment below I try to answer as many as possible and I' ll just saybye for now and 

No comments:

Post a Comment