Android Multilevel ListView Tutorial

This tutorial is about implementing multilevel listviews in your project. I explained by talking an example of music albums where listviews are displayed for list of albums, list of songs under an album.

The first screen will be displayed with list of albums in ListView and the second screen will be displayed with list of songs under an album. Third screen will be displayed with a single song information.

I generated sample json using PHP. You can get php project files along with source code of this project.

Creating new Project

1. Create a new project in your Eclipse IDE by navigating to File ⇒ New ⇒ Android Application Project and fill the required details. Name your main activity as AlbumsActivity.java

2. Create a new package for placing helpers classes. You can create new package by right clicking on project src folder new -> package and naming it as your_package.helper (replace your_package with your actual package name)

3. As our application is connecting to internet, add the required permission in your AndroidManifest.xml file. Also i am adding two more class files (TrackListActivity, SingleTrackActivity) in manifest file.

6. Create a new file called JSONParser.java and paste the following code. This class file used to get json data by making http request. (Please note that this class file only fetches the json from http, it won’t parse the json)

15. Open your TrackListActivity.java and add the following code. In the following code

> First i am receiving album id from the previous activity (which is AlbumsActivity.java)> I am calling a new async background thread called LoadTracks().execute() which will send http request and get songs list under an album (using album id)> Once the data is received i parsed it and displayed in listiview.> Also on selecting a single list item (song) i am launching a new activity named SingleTrackActivity.java by passing album id and song id to it.

18. Open SingleTrackActivity.java file and try following code. In the following code

> From the previous activity TracksListActivity.java, album id and song id is received> a new asyc background thread LoadSingleTrack().execute() is called to get single song information. To get single song information album id and song id is posted as GET parameters.> After fetching json from http, json data is parsed and displayed in view.

Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk: ravi@androidhive.info

Can you consider create a tutorial/serie about design for Android? For example, how to create a nice design and configure the xml based on psd?

Thanks

Jitterydadav

dgagdafg

Sur

Thanks for each and every tutorial you have posted. It has been so helpful.
Can you please post tutorial on generating notification depending upon the time stored on database.
Waiting for your Next Tutorial

Ram Sharan

Hi Ravi, Such a great post,
no words to say, and in simple words
“Stunning” biggest task you have made very easily for learners…Thanks a lot.

I need your help:-
for example: “imagepath” => “www.pizzahut.com.au/images/menu/Pizza-Lge-BBQ_Meatlovers.png” but i am not getting proper link in generated JSON, so please tell me how i need to write image url to fetch images using data.php

k

remove the cots ” ” and put the url in database

deddy

Thanks for the tutorials and all the ideas.

Subhanivizag

Hi Ravi, I m following ur articles, they are very nice. Ravi can u please suggest me any UI designing tool for android, apart from droiddraw. I looking for rich UI interface designing tools.

Florian Froehlich

Tnx Ravi,
can you please explain, how search and filter the entries in the list by an edittext?

thx for this tutorial….
i’m just a beginner and i got error @ jsonParser.makeHttpRequest….
can anyone help me???
T_T

Sanjaypandey00777

Thanks Ravi for this wonderful tutorial . May I know if you have used MySql database in this project??

Codereborn

Hi Ravi
you have post superb tutorial which help me a lot to develop my first android app. Now i have to develop app for IPhone and i am developing this first time. So can anyone suggest some good site like (androidhive) that help me to develop IPhone App.
Thanks.

Sanjaypandey00777

Thanks Ravi . will you please help me?? where to save the php files in eclipse if I change the url to localhost ?? plz reply

Cesar

we need help with this , were do we put the files please

Isla Aloha

Ravi,

Any chance you will show us how to interface with the internal sensors such as the multi-touch screen and the acceleronometer, compass, etc?

Hi Friends anybody tell me i want to display the customer details code name this details when i click button it will go to next screen i will enter code and name after clicking the save Button this details will add to the code ,name in first activity

Martin

Thank you so much, you saved my so much time when I used many of your tutorials for my android application (Goal Do+)!

Abrahim

no doubt, it’s such a great tutorial, but i wanna know how can i work with Multi Level List View with using single JSON only, it means single JSON for both Albums & Music, please make such kind of JSON for us.. 🙂

Kartik Sibal

Learn how to root your andorid visit 0007hacker.wordpress.com/.

Guest

This Tut is great and works. But how do I move on, so I ex. could write some thing about Adobe Flash on page for that and something on another page for Adobe Reader and so on. Where do I put text / pictures for the second page on every item in the list?

Ravi. I need your help in implementing this in the http://viewpagerindicator.com/. Can you post a tutorial on this. I am trying to use the tabbed interface and trying to integrate your list into it. Please help me.

Excellent tutorial , it gives real results when tried and tweaked to suit various needs. Awesom man…
Just curious to know, would you mind posting a lazy loading code for Listviews.

Daniel

Thanks for the tutorial, can i ask you to make Android Multilevel ListView Tutorial without connection internet (offline ) with Sql Lite? i’m soo thankful for that.Thanks before

Fabian

Great Tutorial! I’ve been trying to use Lazy loading with multilevel views but have been facing many performance issues. It would be greta to see a tutorial like this one that includes custom list view with images. Thanks!

Krupa

i want this type of tutorial that will display content with image in multilevel list view

friend

In php site i want to read dynamic array from Mysql so please give me php code for sample

Devi

i can not able to see first listview ….i’ll will give this error but i dont know where i have to mention that content must have Listview whose id attribute is ‘android.R.id.list’
please help me…..

How can i get the same output but without php? i want to just use xml which has data for listview?

Cesar

GUYS GUYS GUYS !!! HOW DO I STORE THE PHPS FOR USING THEM IN OTHER SERVER AND MODIFYING THEM

Cesar

if i store the documents in a web server im not able to make the Json from the php please help any idea of how to store or manage the files for customising them ?

Minh Nhựt Nguyễn

Sorry but I can’t download it!! plz upgrate it!!

garridulu

Does anyone know how to do the same but no using static array? I mean all the data get from mysql database doing a select.

cloudman

hello, I did not understand how to get the id of the selected album?
// send album id to tracklist activity to get list of songs under that album
String album_id = ((TextView) view.findViewById(R.id.album_id)).getText().toString();

the album_id variable is in the tracklist and not in the albumList?? please help

Adnan Alvee

Ravi thanks for the tutorial so much.

I have a problem, I have tons of data in JSON and I want to implement a onScroll Listener.

There are tons of tutorial out there buit so hard to implement since Im a newbie.

I
have successfully implemented the Multilevel listview like yours, can
you help me code a Load on Scroll? Like scroll to 20 items, then it
loads more automatically.

Thanks in advance.

abdul

hi adnan even i m trying to develop same app where i m having .mp3 file
can u plz help me with this problem
Like scroll to 20 items, then it loads more automatically?

Hi Ravi, first of all thanks to your tutorial, my english bad hopefully you understand. I got a question regarding to the multilevel listview, how can i make a dynamic of listview if i do not know how many level do i have in the database?

2a192Nik

Hi Ravi, how do we do this using database. I mean those data you used to generate the list.

Nodirbek

Dear friend, did you find a solution for that I also need to get the data from the database.

Nb2d29a1al

How did you produce the array of data from your data.php?

badname

hi ravi i upload php files in my host but when i need download this file i have ERROR 403 , can help me for fix this ?

However, I have the problem displaying single track details. The details returned null with only the id showing. The logcat also catches the JSON exception. I’m not too sure how to solve the problem as I am still new to the development of android. Please help me. Thank you.

could you do something for me : I need help in making three level expandable list view with json data volley StringRequest…
plz help me…

Rahul Thakur

Thank you so much sir for sharing this tutorial But I just want to intent from one to another through Button clicks in a ListView Row.

hari shankar

Error:(7, 23) error: package org.apache.http does not exist
The code is not working in compileSdkVersion 23 but working in compileSdkVersion 22,18,8

can anyone share me the alternate solution for this!

Sanchit Mahajan

How to display image in above example?

Michael

Thanks @ravi8x:disqus for your tutorial on multilevel listview, it is been so helpful. I’m work on this music app and I want the lyrics to display along as the music plays. Any algorithm? And also what is the best way to save the lyrics, JSON, XML or in a database?
Thanks!

Store them in database. Consider using Realm database as it’s much easier.

Zaid Ahmed

Very nice tutorial..
can you please available same tutorial with firebase.
Thanks in advance

Threef App

Pleased how can I pass paramentros between activitis

aalorwu

Use a Bundle to bundle your parameters and pass it in an intent to the next activity.

Masharov Oleg

Hello, @ravi8x:disqus! I have a problem with “NameValuePair” in this project like “Cannot resolve symbol ‘NameValuePair'”

And I have a problem in “How to connect Android with PHP, MySQL” – there “NameValuePair” –

‘org.apache.http.NameValuePair’ is deprecated

Simon IT

add this to your gradle:

android {
useLibrary ‘org.apache.http.legacy’
}

John

Anyone have anything similar using volley?

Chihab Chihab

in this app the music is included or just information about each album?

thank you

Joseph Mhlanga

Hi Ravi, thanks for the tutorials, u are awesome. Can u please help me i want a multi list view with images and text fetching from database and text and using mysql database and not using static data. Would you help me with the php backend code and the android code.
1.Fetch albums with an image
2.Fetch songs in an album with an image as well
3.Fetch song information full