Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3992268
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:44:39+00:00 2026-05-20T06:44:39+00:00

My Android app needs to populate the ListView using the data from an ArrayList

  • 0

My Android app needs to populate the ListView using the data from an ArrayList.

I have trouble doing this. Can someone please help me with the code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:44:40+00:00Added an answer on May 20, 2026 at 6:44 am

    You need to do it through an ArrayAdapter which will adapt your ArrayList (or any other collection) to your items in your layout (ListView, Spinner etc.).

    This is what the Android developer guide says:

    A ListAdapter that manages a ListView backed by an array of arbitrary objects. By default this class expects that the provided resource id references a single TextView. If you want to use a more complex layout, use the constructors that also takes a field id. That field id should reference a TextView in the larger layout resource.

    However the TextView is referenced, it will be filled with the toString() of each object in the array. You can add lists or arrays of custom objects. Override the toString() method of your objects to determine what text will be displayed for the item in the list.

    To use something other than TextViews for the array display, for instance ImageViews, or to have some of data besides toString() results fill the views, override getView(int, View, ViewGroup) to return the type of view you want.

    So your code should look like:

    public class YourActivity extends Activity {
    
        private ListView lv;
    
        public void onCreate(Bundle saveInstanceState) {
             setContentView(R.layout.your_layout);
    
             lv = (ListView) findViewById(R.id.your_list_view_id);
    
             // Instanciating an array list (you don't need to do this, 
             // you already have yours).
             List<String> your_array_list = new ArrayList<String>();
             your_array_list.add("foo");
             your_array_list.add("bar");
    
             // This is the array adapter, it takes the context of the activity as a 
             // first parameter, the type of list view as a second parameter and your 
             // array as a third parameter.
             ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                     this, 
                     android.R.layout.simple_list_item_1,
                     your_array_list );
    
             lv.setAdapter(arrayAdapter); 
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have android app that talks to server and syncs some data int SQLite
I hope I can explain this properly. I'm making an android app that, when
I'm doing some Android development, and I much prefer Visual Studio, but I'll have
My Android app needs to retrieve information about a contact (namely, phone number and
I've written an Android app that needs the short timezone name in which the
I am developing an Android app that needs to receive specific informations for each
I am developing an Android app which needs to poll a specific webpage in
I have an Android app, where a part of the app is a list
My android app is supposed to go through twitter using twitter4j libraries, and return
In my android app I've got the below code creating my database. This works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.