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

In my Android app, I have some data that needs to be synced daily
I'm making an OpenGLES Android app using Android NDK, expanding from android's gljni example,
I have an Android app which needs to play a sound resource on a
I'm using Sqlite with android to develop and app which can be customizable (for
My android app needs to write a file to a location that can be
My android app needs to fetch some info from a php server that hosts
We have an Android app and a Web Service. We want to download part
I have an Android app with a ListActivity in the main view. The list
I've got an Android app which has a periodic background Service. I want this
I'm writing an Android app where users can upload video to Youtube. I'd like

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.