ListView Tutorial With Example In Android Studio

List of scrollable items can be shown in Android using ListView. It helps you to showing the information as a scrollable list. Users would then be able to choose any list item by clicking on it. ListView is default scrollable so we don’t have to use scroll View or whatever else with ListView.

ListView is broadly used as a part of android applications. An exceptionally normal case of ListView is your phone contact book, where you have a list of your contacts showed in a ListView and if you click on it then user information is shown.

Android ListView Tutorial With Example – Android Studio

Download projct file of  ListView Tutorial With Example – Android Studio

Adapter: To fill the data in a ListView we simply use adapters. List items are automatically inserted to a list using an Adapter that pulls the content from a source such as an arraylist, array or database.

ListView in Android Studio: Listview is present inside Containers. From there you can drag and drop on virtual mobile screen to create it. Alternatively you can also XML code to create it.



Here is Android ListView XML Code:

    android:dividerHeight="1dp" />

Listview look in Design:


In android commonly used adapters are:

  1. Array Adapter
  2. Base Adapter

Now we explain these two adapter in details:

Important Note: By default, ArrayAdapter expects a Layout with a single TextView, If you want to use more complex views means more customization in list items, please avoid ArrayAdapter and use custom adapters.

Below is Array Adapter code:

ArrayAdapter adapter = new ArrayAdapter<String>(this,R.layout.ListView,,StringArray);

Example of list view using Array Adapter:

In this example, we display a list of countries by using simple array adapter. Below is the final output we will create:




Step 1: Create a new project Listexample and activity Main Activity. Here we will create a ListView in LinearLayout. Below is the code of activity_main.xml or content_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""

        android:dividerHeight="1dp" />


Step 2: Create a new activity name Listview and below is the code of activity_list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""

        android:text="fruit list"
        android:textColor="#000000" />


Step 3: Now in this final step we will use ArrayAdapter to display the country names in UI. Below is the code of

package com.andrious.listview;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity {
    // Array of strings...
    ListView simpleList;
    String  FruitList[] = {"Apple", "Banana", "Lemon", "Cherry", "Strawberry", "Avocado"};

    protected void onCreate(Bundle savedInstanceState) {

        simpleList = (ListView)findViewById(;
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.activity_list_item,, FruitList);

Output Screen:

Now run the App in Emulator. You will see the below output screen where list of fruits names will be printed:



2.Base Adapter:

BaseAdapter is a common base class of a general implementation of an Adapter that can be used in ListView. Whenever you need a customized list you create your own adapter and extend base adapter in that. Base Adapter can be extended to create a custom Adapter for displaying a custom list item.  ArrayAdapter is also an implementation of BaseAdapter.

 Example of list view using Custom adapter(Base adapter):

In this example we display a list of countries with flags. For this, we have to use custom adapter as shown in example:


Step 1: Create a new project Listebasexample and activity Main Activity. Here we will create a ListView in LinearLayout. Below is the code of activity_main.xml or content_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""



Step 2: Create a new activity name Listview and below is the code of activity_list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
                android:src="@mipmap/ic_launcher" />
                android:text="Fruit name"
                android:textColor="#000000" />
                android:text="fruit list"
                android:textColor="#000000" />

Step 3: In third step we will use custom adapter to display the country names in UI by coding Below is the code of

Important Note: Make sure flag images are stored in drawable folder present inside res folder with correct naming.

package com.andrious.listview;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity {
    // Array of strings...
    ListView simpleList;
    String  Item[] = {"Apple", "Banana", "Lemon", "Cherry", "Strawberry", "Avocado"};
    String  SubItem[] = {"The apple tree is a deciduous tree in the rose family best known for its sweet, pomaceous fruit, the apple.",
            "The banana is an edible fruit – botanically a berry – produced by several kinds of large herbaceous flowering plants in the genus Musa.",
            "The lemon, Citrus limon Osbeck, is a species of small evergreen tree in the flowering plant family Rutaceae, native to Asia.",
            "A cherry is the fruit of many plants of the genus Prunus, and is a fleshy drupe.",
            "The garden strawberry is a widely grown hybrid species of the genus Fragaria, collectively known as the strawberries.",
            "The avocado is a tree, long thought to have originated in South Central Mexico, classified as a member of the flowering plant family Lauraceae."};
    int flags[] = {, R.drawable.banana, R.drawable.lemon, R.drawable.cherry, R.drawable.strawberrie, R.drawable.avocado};

    protected void onCreate(Bundle savedInstanceState) {

        simpleList = (ListView)findViewById(;
        CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), Item,SubItem, flags);

Step 4: Now create another class Custom Adapter which will extend BaseAdapter. Below is the code of

package com.andrious.listview;

 * Created by MD.ISRAFIL MAHMUD on 12/27/2017.
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class CustomAdapter extends BaseAdapter {
    Context context;
    String Item[];
    String SubItem[];
    int flags[];
    LayoutInflater inflter;

    public CustomAdapter(Context applicationContext, String[] Item, String[] SubItem , int[] flags) {
        this.context = context;
        this.Item = Item;
        this.SubItem = SubItem;
        this.flags = flags;
        inflter = (LayoutInflater.from(applicationContext));

    public int getCount() {
        return Item.length;

    public Object getItem(int i) {
        return null;

    public long getItemId(int i) {
        return 0;

    public View getView(int i, View view, ViewGroup viewGroup) {
        view = inflter.inflate(R.layout.activity_list_item, null);
        TextView item = (TextView) view.findViewById(;
        TextView subitem = (TextView) view.findViewById(;
        ImageView image = (ImageView) view.findViewById(;
        return view;


Now run the App in Emulator and it will show you name of countries along with flags. Below is the output screen:



  1. LastGarrett

    January 11, 2018 at 5:20 pm

    I see you don’t monetize your site, don’t waste your traffic, you can earn additional cash every
    month because you’ve got high quality content. If you want to know how to make extra
    money, search for: Mertiso’s tips best adsense alternative

  2. Justin Marcet

    June 19, 2018 at 1:38 pm

    you’re in reality a excellent webmaster. The site loading pace is amazing. It kind of feels that you’re doing any distinctive trick. Moreover, The contents are masterwork. you’ve done a magnificent job on this matter!

  3. GavinJuicy

    June 25, 2018 at 2:37 am

    I often visit your website and have noticed that you don’t update it often. More frequent updates will give your page higher authority & rank
    in google. I know that writing posts takes a lot of time,
    but you can always help yourself with miftolo’s tools which will shorten the time of creating an article to a few seconds.

  4. Warner Twigg

    July 24, 2018 at 9:12 am

    There are some fascinating points in time in this article however I don’t know if I see all of them middle to heart. There’s some validity however I will take maintain opinion till I look into it further. Good article , thanks and we would like more! Added to FeedBurner as effectively

  5. Buy Shared Proxies

    August 11, 2018 at 7:47 am

    Great post, I conceive people should acquire a lot from this weblog its very user pleasant.


    August 18, 2018 at 9:52 am

    There may be noticeably a bundle to learn about this. I assume you made sure nice factors in features also.

  7. Delila Northum

    August 30, 2018 at 2:02 am

    Black on black in the Charg I’m creepin’ Rub me the right way, you might get a genie B.o.B, black Houdini

  8. Julianne Schnabel

    August 30, 2018 at 6:44 am

    With thanks! Valuable information!

  9. car removals

    September 20, 2018 at 4:27 am

    Thank you for all your work on this site. Debby delights in making time for research and it’s really obvious why. We all notice all about the powerful means you present invaluable strategies on your web blog and even inspire response from other people on that issue so my child is without question studying a lot of things. Have fun with the rest of the year. You are always performing a great job.

  10. furtdso linopv

    October 5, 2018 at 1:30 pm

    You can definitely see your skills in the work you write. The arena hopes for even more passionate writers like you who aren’t afraid to mention how they believe. Always go after your heart.

  11. buying proxy

    October 5, 2018 at 2:45 pm

    This site is mostly a walk-through for the entire info you needed about this and didn’t know who to ask. Glimpse right here, and also you’ll undoubtedly discover it.

  12. Jamaal Sneider

    October 17, 2018 at 6:02 am

    Badsanierung Ingolstadt Sie möchten Ihr Badezimmer in Ingolstadt sanieren, renovieren oder umbauen? Ihr Badumbau soll möglichst wenig Arbeit machen? Die kompetenten Fachleute von FEPA planen und gestalten Ihr Bad neu und koordinieren alle Arbeiten – damit Sie sich um nichts kümmern müssen. Alles aus einer Hand!

  13. BestHassie

    November 12, 2018 at 6:51 am

    I see you don’t monetize your site, don’t waste your traffic, you
    can earn extra bucks every month. You can use the best adsense alternative for
    any type of website (they approve all websites), for more
    details simply search in gooogle: boorfe’s tips monetize your website

  14. JaimieJuicy

    November 23, 2018 at 7:31 am

    Hi. I see that you don’t update your website too often. I know that writing articles is time consuming and boring.
    But did you know that there is a tool that allows you to create new posts using existing
    content (from article directories or other pages from your niche)?
    And it does it very well. The new posts are unique and pass the copyscape
    test. Search in google and try: miftolo’s tools

  15. board

    November 24, 2018 at 9:32 pm

    Hi! This is my 1st comment here so I just wanted to give
    a quick shout out and tell you I really enjoy reading through your
    blog posts. Can you suggest any other blogs/websites/forums that deal with the same subjects?

    Thanks for your time!

  16. Chas Defusco

    November 28, 2018 at 4:38 am

    Greetings! I know this is kind of off topic but I was wondering if you knew where I could find a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having problems finding one? Thanks a lot!

  17. Un Woullard

    November 30, 2018 at 2:16 am

    Hiya, I like your post. I recently finished an post on storing food. I like to make my own gammon for Fall!. I will be creating a basic dessert to go with it. The children will be on holiday and I am positive they are going to love it.

  18. Lauren Blakely Unzipped ebook

    December 13, 2018 at 9:13 pm

    I’m truly enjoying the design and layout of your blog.
    It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a designer to create your
    theme? Great work!

  19. JeanettBig

    December 18, 2018 at 12:08 am

    Hello. I have checked your and i see you’ve
    got some duplicate content so probably it is the reason that you don’t rank high in google.
    But you can fix this issue fast. There is a tool
    that creates content like human, just search in google: miftolo’s tools

  20. loans with no credit check

    January 1, 2019 at 6:27 am

    Hey, I just found your blog and I agreed with this article particularly. . Where may I find out more?

  21. no credit check loans georgia

    January 7, 2019 at 2:21 am

    Hi, I discovered your blog and I resonated with this post the most. . Where might I find out more?

  22. Eric

    January 10, 2019 at 4:16 am

    I got this web site from my pal who informed
    me about this website and now this time I am visiting this web page
    and reading very informative articles or reviews at this time.

  23. webpage

    January 16, 2019 at 11:03 am

    This makes more sense than most…

  24. loans las vegas no credit check

    February 8, 2019 at 8:11 am

    TY for this piece, it has been quite helpful to me! Way simpler than anything else out there.

  25. Enrique Moothart

    February 9, 2019 at 6:33 pm

    Fliesenleger Landshut – Wir laden Sie ein sich mit dem Angebot von vertraut zu machen. Zu unserem Leistungsangebot gehört das Verlegen von Fliesen, Mosaik und Natustein im Raum Landshut, Augsburg, Regensburg und Ingolstadt. Außerdem sind wir der richtige Ansprechpartner wenn es um komplette Sanierungen (z.B. Badgestaltung) und Badumbau geht.bDas Verlegen von Laminat und Trockenbau rundet unser Leistungsangebot ab. Lassen Sie sich von uns beraten und nehmen Sie gleich Kontakt mit uns auf.

  26. minecraft

    April 11, 2019 at 8:24 am

    I am curious to find out what blog system you’re utilizing?

    I’m experiencing some minor security issues with my latest site and I would like
    to find something more safe. Do you have any suggestions?

  27. minecraft

    April 15, 2019 at 1:48 am

    Howdy! I’m at work surfing around your blog from my new iphone 3gs!
    Just wanted to say I love reading through your blog and look forward to all your posts!
    Keep up the excellent work!

  28. minecraft

    April 18, 2019 at 9:08 am

    Admiring the time and effort you put into your blog and detailed information you provide.
    It’s good to come across a blog every once in a while
    that isn’t the same unwanted rehashed material. Excellent read!
    I’ve bookmarked your site and I’m adding your RSS feeds
    to my Google account.

  29. minecraft

    April 19, 2019 at 7:19 am

    Ahaa, its pleasant conversation concerning this piece of writing
    at this place at this website, I have read all that, so at this time me also commenting here.

  30. minecraft

    April 22, 2019 at 2:08 am

    I like the valuable info you supply in your articles.
    I will bookmark your blog and take a look at once more right here frequently.
    I’m somewhat sure I’ll be informed a lot of new stuff right right here!
    Good luck for the following!

  31. minecraft

    April 23, 2019 at 7:48 am

    I used to be suggested this web site via my cousin. I’m not positive whether or not this
    submit is written by him as nobody else recognise such specific about
    my trouble. You are incredible! Thank you!

  32. minecraft

    April 23, 2019 at 8:38 pm

    I am now not certain the place you are getting your info, but
    good topic. I needs to spend a while finding out much more or
    figuring out more. Thanks for great information I was on the lookout
    for this information for my mission.

  33. Jefferson Zanes

    May 12, 2019 at 3:36 am

    Hmm is anyone else experiencing problems with the pictures on this blog loading? I’m trying to determine if its a problem on my end or if it’s the blog. Any suggestions would be greatly appreciated.|

  34. no credit and need a loan

    May 19, 2019 at 8:34 am

    You give some half-hearted statements.

  35. Orville Launiere

    May 20, 2019 at 10:05 pm

    A motivating discussion is definitely worth comment. I do believe that you ought to publish more on this subject matter, it might not be a taboo matter but usually people do not discuss such topics. To the next! Kind regards!!|

  36. Scott Smithe

    May 20, 2019 at 10:14 pm

    I am regular visitor, how are you everybody? This article posted at this site is truly pleasant.|

  37. Jadwiga Quittner

    May 20, 2019 at 10:16 pm

    Normally I don’t read post on blogs, but I would like to say that this write-up very compelled me to try and do so! Your writing style has been surprised me. Thank you, very nice post.|

  38. Erich Murnock

    May 20, 2019 at 10:18 pm

    Hey there! This post could not be written any better! Reading this post reminds me of my previous room mate! He always kept talking about this. I will forward this post to him. Fairly certain he will have a good read. Thanks for sharing!|

  39. Maryalice Lotridge

    May 20, 2019 at 10:20 pm

    Definitely believe that which you stated. Your favourite justification appeared to be at the net the easiest thing to understand of. I say to you, I certainly get annoyed even as people think about worries that they plainly do not know about. You controlled to hit the nail upon the top as smartly as defined out the entire thing with no need side-effects , folks can take a signal. Will likely be back to get more. Thanks|

  40. Rashad Courtnage

    May 20, 2019 at 10:20 pm

    Hey! This is my first comment here so I just wanted to give a quick shout out and say I really enjoy reading your posts. Can you recommend any other blogs/websites/forums that go over the same subjects? Thank you!|

  41. Brain Summerford

    May 20, 2019 at 10:21 pm

    This info is invaluable. When can I find out more?|

  42. Esteban Torrain

    May 20, 2019 at 10:21 pm

    Howdy! Someone in my Facebook group shared this website with us so I came to check it out. I’m definitely enjoying the information. I’m bookmarking and will be tweeting this to my followers! Great blog and amazing design.|

  43. Robbie Ingrahm

    May 20, 2019 at 10:25 pm

    Hello! I know this is kind of off-topic but I needed to ask. Does building a well-established blog such as yours require a lot of work? I’m completely new to blogging but I do write in my journal every day. I’d like to start a blog so I will be able to share my own experience and feelings online. Please let me know if you have any kind of ideas or tips for brand new aspiring blog owners. Thankyou!|

  44. Woodrow Venturella

    May 20, 2019 at 10:31 pm

    Thank you for the good writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! However, how could we communicate?|

  45. Nicola Audet

    May 20, 2019 at 10:31 pm

    Hi everyone, it’s my first pay a quick visit at this web site, and piece of writing is truly fruitful designed for me, keep up posting these posts.|

  46. Rochell Bubbico

    May 20, 2019 at 10:32 pm

    hey there and thank you for your info – I have certainly picked up anything new from right here. I did however expertise a few technical points using this web site, as I experienced to reload the website lots of times previous to I could get it to load properly. I had been wondering if your web host is OK? Not that I’m complaining, but slow loading instances times will often affect your placement in google and could damage your high-quality score if advertising and marketing with Adwords. Well I am adding this RSS to my email and could look out for a lot more of your respective fascinating content. Ensure that you update this again soon.|

  47. Leslee Sossaman

    May 20, 2019 at 10:32 pm

    Hello, i think that i saw you visited my blog thus i came to return the favor?.I am attempting to find issues to enhance my site!I suppose its ok to use a few of your ideas!!|

  48. Wanda Unsicker

    May 20, 2019 at 10:32 pm

    Wow, superb weblog format! How long have you ever been blogging for? you make running a blog look easy. The full look of your website is excellent, let alone the content!

  49. Elden Graci

    May 20, 2019 at 10:34 pm

    Everything is very open with a very clear description of the challenges. It was truly informative. Your site is very helpful. Thanks for sharing!|

  50. Minh Haugland

    May 20, 2019 at 10:37 pm

    Thanks for finally talking about > blog_title < Liked it!|

  51. Shaunna Sichta

    May 20, 2019 at 10:38 pm

    Heya i am for the primary time here. I found this board and I find It truly helpful & it helped me out a lot. I hope to provide something again and help others like you helped me.|

  52. Sidney Cairns

    May 20, 2019 at 10:39 pm

    I always emailed this web site post page to all my friends, as if like to read it then my links will too.|

  53. Shirly Arimoto

    May 20, 2019 at 10:41 pm

    When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get three e-mails with the same comment. Is there any way you can remove me from that service? Thanks a lot!|

  54. Alecia Gullage

    May 20, 2019 at 10:47 pm

    Hi i am kavin, its my first time to commenting anyplace, when i read this article i thought i could also create comment due to this sensible post.|

  55. Royce Kinkaid

    May 20, 2019 at 10:50 pm

    Hi, Neat post. There’s a problem along with your web site in web explorer, would test this? IE nonetheless is the market chief and a big component to other folks will omit your wonderful writing due to this problem.|

  56. Garth Harps

    May 20, 2019 at 10:53 pm

    It’s very straightforward to find out any matter on net as compared to textbooks, as I found this article at this web site.|

  57. Rocky Blakeman

    May 20, 2019 at 10:54 pm

    I’m no longer sure where you’re getting your info, however good topic. I needs to spend a while finding out much more or figuring out more. Thank you for magnificent information I used to be searching for this information for my mission.|

  58. Lydia Bleazard

    May 20, 2019 at 10:58 pm

    Everything is very open with a clear explanation of the issues. It was really informative. Your site is extremely helpful. Thanks for sharing!|

  59. Lashon Guilliams

    May 20, 2019 at 11:00 pm

    Hi, I do think your website could possibly be having web browser compatibility issues. Whenever I take a look at your site in Safari, it looks fine however, when opening in I.E., it’s got some overlapping issues. I merely wanted to give you a quick heads up! Aside from that, great site!|

  60. Kristian Sidberry

    May 20, 2019 at 11:00 pm

    I do not know whether it’s just me or if everybody else experiencing issues with your site. It appears like some of the text on your content are running off the screen. Can somebody else please comment and let me know if this is happening to them too? This may be a issue with my web browser because I’ve had this happen before. Thank you|

  61. Jordon Valladao

    May 20, 2019 at 11:03 pm

    Hello to all, how is the whole thing, I think every one is getting more from this web site, and your views are nice designed for new users.|

  62. Shantelle Mojica

    May 20, 2019 at 11:06 pm

    Hi this is kinda of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding skills so I wanted to get guidance from someone with experience. Any help would be enormously appreciated!|

  63. Ike Heimsoth

    May 20, 2019 at 11:11 pm

    Hey there! Do you know if they make any plugins to safeguard against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any recommendations?|

  64. Jaquelyn Chmelik

    May 20, 2019 at 11:14 pm

    We are a group of volunteers and starting a new scheme in our community. Your website provided us with valuable info to work on. You have done a formidable job and our entire community will be thankful to you.|

  65. Fermin Reineck

    May 20, 2019 at 11:15 pm

    Aw, this was an exceptionally good post. Taking the time and actual effort to create a very good article… but what can I say… I hesitate a lot and never seem to get nearly anything done.|

  66. how to get help in windows 10

    May 21, 2019 at 10:41 pm

    This is my first time go to see at here and i am really
    pleassant to read everthing at alone place.

  67. gamefly free trial

    May 23, 2019 at 3:18 am

    Your style is so unique compared to other folks I have read stuff
    from. I appreciate you for posting when you’ve got the opportunity, Guess I’ll just bookmark this blog.

  68. Free Stuff

    May 28, 2019 at 7:00 am

    I have seen lots of useful things on your web-site about computer systems. However, I have the judgment that lap tops are still not quite powerful more than enough to be a sensible choice if you generally do projects that require a great deal of power, like video modifying. But for internet surfing, microsoft word processing, and most other frequent computer functions they are perfectly, provided you don’t mind the tiny screen size. Many thanks sharing your opinions.

Leave a Reply