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

  • SEARCH
  • Home
  • 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 5960463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:49:47+00:00 2026-05-22T18:49:47+00:00

I have an ArrayList of an object which has properties Object.name and Object.url .

  • 0

I have an ArrayList of an object which has properties Object.name and Object.url.

I want to loop through the ArrayList and apply the Object’s “name” to an android ListView. I also want to keep the Object’s other properties in tact, so that i can call the “url” property in the onClick method.

What i have now is this:

main_list.setAdapter(new ArrayAdapter<RomDataSet>(this, android.R.layout.simple_list_item_1, android.R.id.text1, mRoms));

But clearly that is not what I need…

Any help would be appreciated 🙂

  • 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-22T18:49:48+00:00Added an answer on May 22, 2026 at 6:49 pm

    1.) You have your ArrayList:

    main_list
    

    2.) Create a ListView in your XML file (say, main.xml) and grab its id. That is, given:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ListView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/liveFeed"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
    </LinearLayout>
    

    Do something like this:

    ListView livefeed = (ListView)this.findViewById(R.id.liveFeed);
    

    within your activity (if you’re in somewhere else such as an OnClickListener, replace the “this” with the View variable that was passed as a variable into the OnClickListener).

    3.) Define your ArrayAdapter. Note that one of its parameters (the third one in your case) will be a TextView id. This is because the ArrayAdapter class, by default, returns a TextView in the ListView. If you override the ArrayAdapter class, you can use custom layouts to have items with custom Views within your ListView, but this is not necessary for what you’ve outlined in your question, and it seems like you’ve got it already.

    4.) Set the adapter to the ListView (given an ArrayAdapter named ‘aa’):

    livefeed.setAdapter(aa);
    

    Now the way the ArrayAdapter works is it invokes each Object’s toString() method and sets each TextView in the ListView to this String. So make a toString() method in your Object’s class that returns its name property:

    public String toString(){return name;} //assuming name is a String
    

    Also note that, if you add Objects to the ArrayList, notify the ArrayAdapter that you have so it can accordingly update your ListView with the modifications (given an ArrayAdapter named ‘aa’):

    aa.notifyDataSetChanged();
    

    Let me know if you need any more help. As always, check the answer check mark if this answered your question.

    Also note that, at one point you may wish to cross reference your ArrayAdapter and ArrayList between your activity and Object class. It’s very helpful to make these fields static in order to do so.

    EDIT:

    You wanted to also know how to access a specific Object when you click on an item in the ListView. Here it is (given your ListView is named livefeed):

    livefeed.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
    
        //in here you may access your Object by using livefeed.getItemAtPosition(position)
        //for example:
            Object current = livefeed.getItemAtPosition(position);
            //do whatever with the Object's data
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object config which has some properties. I can export this ok,
I have an ArrayList, which includes a number of items I want to remove.
Basically, I have a Container class called Employees which has in it an ArrayList.
I have an ArrayList<String> that I'd like to return a copy of. ArrayList has
I have an ArrayList<String> , and I want to remove repeated strings from it.
I have an arraylist that contains items called Room. Each Room has a roomtype
I have some data stored as ArrayList . And when I want to backup
I need to make an ArrayList of ArrayLists thread safe. I also cannot have
I have a Controller bean (SearchController) that has two managed bean as managed properties
I have a java backing bean which has a method (call it getDataList() )

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.