List View App Android Studio Tutorial Using Custom Adapter

  Рет қаралды 11,144

Code With Cal

Code With Cal

Күн бұрын

In this tutorial we build a simple List View app in Android Studio using Java.
I will demonstrate how to build a list view using a custom adapter. Our adapter class is going extend ArrayAdapter.
We will also implement an on click listener for our list view. So that when you tap on any given row in our list we will taken to a detail activity. To achieve this we will pass our selected item to our detail activity via an intent using put extra.
Our List View will use a custom class of Shape for this example to populate each row. The principles applied here could be used for any custom class that you would like to create a list view for.
Shape List Images:
drive.google.com/drive/folder...
Tutorial 1 (This video) - How to build a List View
Source Code: github.com/codeWithCal/Shapelist
Link: • List View App Android ...
Tutorial 2 - Search and Filter List View:
Source Code: github.com/codeWithCal/Shapel...
Link: • Filter & Search List V...
Tutorial 3 - ListView with search, filter, sort & toolbar:
Link: • Sort List View Android...
Tutorial 4 - ListView Multi-select filters:
Link: • How to Filter List Vie...
⏱️TIMESTAMPS
00:00 - Intro
00:25 - Set up
01:20 - Shape Class
02:19 - Layouts
03:59 - Adapter
07:29 - List Activity
10:52 - On Click Listener
13:19 - Detail Activity
15:43 - Testing
#ListView #AndroidStudio #AppDevelopment #CustomAdapter

Пікірлер: 37
@Gameslease
@Gameslease 2 жыл бұрын
thanks man, you helped me a lot in college with this video.
@rizkymahendra5732
@rizkymahendra5732 3 жыл бұрын
Somehow i found your channel, useful tutorial for me, i wish you have better future on your channel. Thanks for the tutorial!
@CodeWithCal
@CodeWithCal 3 жыл бұрын
Thanks. Glad you found some use in the tutorial :)
@IndialovesyouBJP2024
@IndialovesyouBJP2024 3 жыл бұрын
Sir thank you soo much sir! great work! i will share it with all my friends!
@thanglemon5958
@thanglemon5958 Жыл бұрын
Thank you so much, I really really appreciate that, keep up the good work bro :)
@CodeWithCal
@CodeWithCal Жыл бұрын
🙏
@yourfingeronscreen8598
@yourfingeronscreen8598 3 жыл бұрын
Your tutorials are great, a sunshine ray of java through all that Kotlin stuff on all the Internet. At universities in general, they require java a lot. All I know I learned from your channel, thanks!
@rabiulhasannayan8220
@rabiulhasannayan8220 3 жыл бұрын
very effective tutorial.if you continue like this, your channel will grow a lot some thing to improve. 1. audio quality(it seems like you using computer built in microphone to record). 2. plz zoom the text.so that it more viewable.
@CodeWithCal
@CodeWithCal 3 жыл бұрын
Thanks for the feedback 😊
@vladstici5466
@vladstici5466 3 жыл бұрын
Thanks
@stepbroslive9554
@stepbroslive9554 2 жыл бұрын
Great tutorial, it really helped. Every thing loads fine the first time the activity is ran, however if I go to another activity then return the list is doubled. How can I save the progress on a page so it is the same each time I load it?
@khalednooreldeen4399
@khalednooreldeen4399 3 жыл бұрын
Thanks a million Cal for the outstanding tutorial. Works like a charm!! I just have one question, when scroll down the listview and click on any item (item number 30 for example) , it goes to its detailed activity perfectly. But when i get back to the listview again, the list starts all over from the beginning (from item number 1), not from the item which I clicked. Is there a way to do that? That would be really appreciated.
@CodeWithCal
@CodeWithCal 3 жыл бұрын
Glad you liked the tutorial 🙂 If you made the cell height fixed say for example 100dp. Currently if the user selects say item 30 you'll pass the item via the intent into detail activity. What you'll need to do is override the onbackpressed method on the detail activity and pass that item back to to the list view activity via an intent I'm pretty sure is possible. then calculate to set the scroll view position say 30 times 100. Then set the listview scroll view. I haven't done it myself so some of my assumptions may be incorrect. But give it a go and if you have any dramas let me know
@Lucee220
@Lucee220 11 ай бұрын
@CodeWithCal Great tutorial! My listview loads up perfectly but the onclick is not working when I select an item from the list, instead, the program crashes. I've looked at the other .java files and I can't find any issues. Would you mind taking a look at my code?
@Seafairlynn
@Seafairlynn 3 жыл бұрын
Hi! At 10:52 you went over the OnClickListener about booting up a new activity on click, and I'll like to ask, I'll like to modify each different shape to link to a different type of activity every time, for example, clicking the triangle would open up Activity1.java, with the hexagon opening up Activity2.java with vastly different content. How would I go about modifying the OnClickListener to do this? Thank you so much in advance.
@CodeWithCal
@CodeWithCal 3 жыл бұрын
So in onItemClick() You could open different activities based on the shape name so below Shape selectShape = (Shape) (listView.getItemAtPosition(position)); if(selectedShape.name.contains("Circle")) { // circle intent } else if(selectedShape.name.contains("Square")) { // square intent } else { // default click action } Is that what you are after?
@Seafairlynn
@Seafairlynn 3 жыл бұрын
@@CodeWithCal Yes, it took a bit of tweaking, but thank you so much! I can continue with my project now. If anyone in the future needs it, here's my slightly edited code: private void setUpOnClickListener() { //go to another page listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Shape selectShape = (Shape) (listView.getItemAtPosition(position)); if(selectShape.name.contains("Circle")) { // circle intent Intent showDetail = new Intent(getApplicationContext(), myclassname.class); startActivity(showDetail); } else if(selectShape.name.contains("Square")){ // square intent Intent showDetail2 = new Intent(getApplicationContext(), myclassname2.class); startActivity(showDetail2); } else{ // default click action println("Howdy"); //this can be whatever you want } } }); } Also, you may need to change in Shape.java private String name; to public String name; for this to work, just a disclaimer as I've only been up to Part 2 of this tutorial so I won't know if this change may affect the later tutorials. (All of Part 2 still works otherwise)
@CodeWithCal
@CodeWithCal 3 жыл бұрын
@@Seafairlynn Great work ☺️
@kirazami2282
@kirazami2282 2 жыл бұрын
Hi Cal, do you happen to know why my listview is duplicating cells ? thanks a lot
@CodeWithCal
@CodeWithCal 2 жыл бұрын
The code that populates the list is probably being called more times than you are hoping for. Put in a break point and run in debug mode to see how many times it is called
@ciel_motos
@ciel_motos 3 жыл бұрын
How do I create an action to open a new activity when I click on an item in the list?
@CodeWithCal
@CodeWithCal 3 жыл бұрын
10:52
@user-be7qj5pg8u
@user-be7qj5pg8u Жыл бұрын
i have a problem. when i click view it show "building name" and no image. please help me
@m-j-y8289
@m-j-y8289 3 жыл бұрын
Could you do a video where you show how to add and delete things from the list as well?
@CodeWithCal
@CodeWithCal 3 жыл бұрын
kzfaq.info/get/bejne/atFhjbChtJ--nmQ.html Maybe a bit more than what you asking for. But check out the SQLite tutorial, we delete items from the list in this tutorial.
@m-j-y8289
@m-j-y8289 3 жыл бұрын
@@CodeWithCal Thanks will do!
@Asma-od1vf
@Asma-od1vf 2 жыл бұрын
Hi cal .. I try to write your code but i need your help to resolve my problem please am student and i really really need your help
@CodeWithCal
@CodeWithCal 2 жыл бұрын
Sure, I'll give it a go. Whats the problem?
@Asma-od1vf
@Asma-od1vf 2 жыл бұрын
@@CodeWithCal thank u so much ... The problem when I press in shape_cell the app is stopped suddenly.. I do not know what is problem ?
@CodeWithCal
@CodeWithCal 2 жыл бұрын
@@Asma-od1vf you should be getting an error message in your console. Open up the console and look for something with the term exception in it then google that :)
@krmoralesg502
@krmoralesg502 3 жыл бұрын
put your paypal account so I can give you some money if I get the job. thanks for everything, learned a lot, coming from java and definitely android is a lot more abstract than normal java, I will take some time to get use to the built in classes that android studio has.
@CodeWithCal
@CodeWithCal 3 жыл бұрын
paypal.me/ccahillapps Please feel zero obligation, I'm happy to help for the sake of helping. Good luck, fingers crossed you land the job you are after 🍀🤞
@ultimat.
@ultimat. 3 жыл бұрын
Bonjour, je sais pas si vous allez pouvoir me donner l'info. J'ai créé une liste view et je croyais pouvoir attacher une autre liste wiew mais je n'y arrive pas. Mon projet et de présenter des articles de péche et pour cela j'ai besoin de créer des catégories exemples A1) matériels de pêche et B1) matériels vêtements de pêche sous catégories Aa1 accessoires de pêche les bouchons Ab1 les apats Ac1 les Cannes à pêche.... et une dernière sous catégorie Aaa1 les bouchon bois Aaa2 les bouchons pvc Aaa3 les bouchons..... Et après la fiche de l'article. Comment procéder. J'ai cherché et rien trouvé si vous pouviez m'orienter ou me donner une source ou autre je suis preneur. Merci beaucoup par avance.
@CodeWithCal
@CodeWithCal 3 жыл бұрын
Bonjour. Google translate lead me to believe you're trying to build an expandable list view? www.journaldev.com/9942/android-expandablelistview-example-tutorial Hope this helps. Merci, mon ami.
@MK-hu8kc
@MK-hu8kc 3 жыл бұрын
@@CodeWithCal This made me laugh when i needed it the most after tirelessly finishing Uni work thanks Cal 😂
@salehhussain7902
@salehhussain7902 3 жыл бұрын
I'm just wondering how are you able to write in this small-sized text?? Seriously regardless of the viewers!
@CodeWithCal
@CodeWithCal 3 жыл бұрын
Thanks for the feedback, I have made the text size bigger in Android Studio for future videos.
RecyclerView | Everything You Need to Know
25:07
Practical Coding
Рет қаралды 130 М.
That's how money comes into our family
00:14
Mamasoboliha
Рет қаралды 10 МЛН
Did you believe it was real? #tiktok
00:25
Анастасия Тарасова
Рет қаралды 53 МЛН
I CAN’T BELIEVE I LOST 😱
00:46
Topper Guild
Рет қаралды 108 МЛН
Русалка
01:00
История одного вокалиста
Рет қаралды 5 МЛН
Count Up Timer App Android Studio Tutorial
9:36
Code With Cal
Рет қаралды 28 М.
Color Picker Android Studio Kotlin Custom Spinner Tutorial
9:39
Code With Cal
Рет қаралды 8 М.
Binding Adapters - Data Binding | Android Studio Tutorial
14:01
Stevdza-San
Рет қаралды 13 М.
Building an adaptive layout with SlidingPaneLayout
21:27
Android Developers
Рет қаралды 17 М.
Эй Рамазан # DamirAgroDizel
0:17
DamirAgroDizel
Рет қаралды 7 МЛН
Козы Едят Траву за Деньги
0:31
РЕТАРД
Рет қаралды 1,5 МЛН
#armenia
1:01
NS Production
Рет қаралды 3,3 МЛН
Golden gadget 😍 New gadgets latest kitchen utensils #shorts
0:12
Golden Gadget
Рет қаралды 6 МЛН
Smart Appliances! New Gadgets, Versatile Utensils, Tool Items #shorts #gadgets 149
0:15