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 8732141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:22:58+00:00 2026-06-13T09:22:58+00:00

I have, the following class. public class BkmCollect extends ArrayList<Bkmark> { public static BkmCollect

  • 0

I have, the following class.

public class BkmCollect extends ArrayList<Bkmark> {

    public static BkmCollect getTestBkm(Context context) {
        BkmCollect bookmarks = new BkmCollect ();

        String[] titles  = context.getResources().getStringArray(R.array.bookmark_titles);
        String[] urls    = context.getResources().getStringArray(R.array.bookmark_urls);
        TypedArray icons = context.getResources().obtainTypedArray(R.array.bookmark_icons);

        for (int i = 0; i < titles.length; i ++) {
            bookmarks.add(titles[i], urls[i], icons.getDrawable(i));
        }

        return bookmarks;
    }
}

The “add” method is implemented at this class. And the “Bkmark” class is another class created at my project.
I want to create a ListView that will get the data from the BkmCollect.getTestBkm method. How can I do this inside my onCreate method? Thanks!

XML file that contain the fields to be inserted at the ListView:

<resources>
    <string-array name="bookmark_titles">
        <item>Google</item>
        <item>Bing</item>
        <item>Gmail</item>
    </string-array>

    <string-array name="bookmark_urls">
        <item>http://www.google.com</item>
        <item>http://www.bing.com/</item>
        <item>http://www.gmail.com</item>
    </string-array>

    <array name="bookmark_icons">
        <item>@drawable/google</item>
        <item>@drawable/bing</item>
        <item>@drawable/gmail</item>
    </array>
</resources>

I am trying to do something like this:

ListView lv = (ListView) findViewById(R.id.favoritos_listView);
ArrayAdapter adapter;
Context context = getApplicationContext();
ArrayList<Bkmark> my_array = BkmCollect .getTestBkm(context);
adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, my_array);
lv.setAdapter(adapter);

enter code here

  • 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-06-13T09:22:58+00:00Added an answer on June 13, 2026 at 9:22 am

    Create a ListView in your layout.xml file, and retrieve it in java by doing a

    ListView lv = (ListView)findViewById(R.id.your_list_view_id);
    

    and populate the listview by doing this:

    ArrayList<String> my_array_list = new ArrayList<String>();
    new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, my_array_list);
    lv.setAdapter(arrayAdapter); 
    

    EDIT

    Say for instance that you have a method where you add some object to an ArrayList

    public ArrayList<String> getPopulatedArrayList() {
        ArrayList<String> myList = new ArrayList<String>();
        myList.add("One");
        myList.add("Two");
        myList.add("Three");
    
        return myList; 
    }
    

    And in you onCreate method

    ArrayAdapter adapter;
    ListView lv;
    lv = (ListView)findViewById(R.id.my_list);
    
    ArrayList<String> list = getPopulatedArrayList(); 
    adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, list);
    lv.setAdapter(adapter); 
    

    Remeber that this only works for List with one TextView, if you need more data in your list, you should create your own class which extends BaseAdapter. An example on this can be found here

    Nothing can be unclear now? If so, just add a comment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class: public class Go { public static void main(String args[])
I have the following class: public abstract class AbstractParent { static String method() {
I have the following class: public class Data { static public SqlDataReader ExecutSql(string sql)
I have the following class: public class getURLData extends AsyncTask<String, Integer, String>{ @Override protected
I have the following class public class MenuVeiculo { public string Nome { get;
I have the following class public class UIControl { public string FName{ get; set;
I have the following class public class CountrySpecificPIIEntity { public string Country { get;
I have the following class public class CountrySpecificPIIEntity { public string Country { get;
I have the following class: public class Movie { string Name get; set; string
I have the following class: public class MainActivity extends Activity { /** Called when

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.