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.
Boomarkdoesn’t need to extendArrayList. 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.
Then create your Bookmark Adapter
The
row_bookmark.xmlPut this in your
ActivityxmlTo populate the list in your activity
To get the URL when a list item is selected you need to set the item click listener