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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:19:46+00:00 2026-06-13T12:19:46+00:00

I have this class: public class Bookmark extends ArrayList<Bkm> { public static Bookmark getBookmark(Context

  • 0

I have this class:

public class Bookmark extends ArrayList<Bkm> {

    public static Bookmark getBookmark(Context context) {
        Bookmark bookmarks = new Bookmark ();

        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 class has the “getBookmark” method that returns a “bookmarks” object, it contains the fields “titles”, “urls” and “icons”. How can I get these fields in my main class? I want to create a ListView with the “titles” items and access the corresponding url in a WebView.

In my main class I have this ListView

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

I am trying to get the data that way

Context context = getApplicationContext();        
ArrayList<Bookmark> my_array = BookmarkCollection.getTestBookmarks(context);
ArrayAdapter<Bookmark> aa = new ArrayAdapter<Bookmark>(context, R.array.bookmark_titles, android.R.layout.simple_list_item_1, my_array);
ListView lv = (ListView) findViewById(R.id.favoritos_listView);
lv.setAdapter(aa);

But the ListView does not appears.

  • 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-13T12:19:47+00:00Added an answer on June 13, 2026 at 12:19 pm

    Boomark doesn’t need to extend ArrayList. What you need to do is create a custom Adapter for your Bookmark objects and use that adapter on your ListView.

    First create your Bookmark model class.

    public class Bookmark {
    
        private String title;
        private String url;
        private Drawable icon;
    
        public Bookmark(String title, String url, Drawable icon) {
    
            this.title = title;
            this.url = url;
            this.icon = icon;
        }
    
        public String getTitle() {
            return title;
        }
    
        public void setTitle(String title) {
            this.title = title;
        }
    
        public String getUrl() {
            return url;
        }
    
        public void setUrl(String url) {
            this.url = url;
        }
    
        public Drawable getIcon() {
            return icon;
        }
    
        public void setIcon(Drawable icon) {
            this.icon = icon;
        }
    }
    

    Then create your Bookmark Adapter

    public class BookmarkAdapter extends BaseAdapter{
    
        private ArrayList<Bookmark> bookmarks;
        private Context context;
    
        public BookmarkAdapter(Context context, ArrayList<Bookmark> bookmarks) {
    
            this.context = context;
            this.bookmarks = bookmarks;
        }
    
        public int getCount() {
    
            return bookmarks.size();
        }
    
        public Object getItem(int position) {
    
            return bookmarks.get(position);
        }
    
        public long getItemId(int arg0) {
    
            return 0;
        }
    
        public View getView(int position, View convertView, ViewGroup parent) {
    
             View row = convertView;
               if ( row == null ) {
    
                   row = View.inflate( context, R.layout.row_bookmark, null );
               }
    
               Bookmark bookmark = (Bookmark)getItem(position);
    
               if (  bookmark!= null ) {
    
                   TextView name = (TextView) row.findViewById( R.id.title );
    
                   if ( name != null ) {
    
                       name.setText( bookmark.getTitle() );
                   }
               }
    
               return row;
        }
    }
    

    The row_bookmark.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    
    </RelativeLayout>
    

    Put this in your Activity xml

    <ListView
        android:id="@+id/bookmark_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>
    

    To populate the list in your activity

       String[] titles  = getResources().getStringArray(R.array.bookmark_titles);
       String[] urls    = getResources().getStringArray(R.array.bookmark_urls);
       TypedArray icons = getResources().obtainTypedArray(R.array.bookmark_icons);
    
       ArrayList<Bookmark> bookmarks = new ArrayList<Bookmark>();
    
       for (int i = 0; i < titles.length; i ++) {
    
           bookmarks.add(new Bookmark(titles[i], urls[i], icons.getDrawable(i)));
       }
    
       ListView bookmarkList = (ListView)findViewById(R.id.bookmark_list);
       bookmarkList.setAdapter(new BookmarkAdapter(this, bookmarks));
    

    To get the URL when a list item is selected you need to set the item click listener

    bookmarkList.setOnItemClickListener(new OnItemClickListener() {
    
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    
                String url = ((Bookmark)parent.getAdapter().getItem(position)).getUrl();
            }
        });
    
    • 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 BkmCollect extends ArrayList<Bkmark> { public static BkmCollect
i have this class: public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { ImageFromWeb ifw;
I have this class: public class Test { public static void main(String[] args) {
i have this class public class Image { public string url { get; set;
I have this class: public static class CsvWriter { private static StreamWriter _writer =
I have this class: public MyClass { public void initialize(Collection<String> data) { this.data =
I have this class: public class Source extends Node { protected DistributionSampler delay ;
I have this Class: public class User { public string id{ get; set; }
I have this class : public class TempFileRef { public readonly string FilePath; public
I have this class public class wordObject implements java.io.Serializable { String wordName; int occCount;

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.