I have been trying to learn how to develop an Android app using the "Master/Detail Flow" in Eclipse.
My problem is that I cannot understand how to create my own ArrayAdapter (So I can change the colors of each line, etc etc) that pretty much looks the same but will take "LibHome.ITEMS" (An Object? as opposed to a simple array.
I can't really understand how to make this work. I also do not wish to blindly adapt another solution rather than learn.
setListAdapter(
new ArrayAdapter<LibHome.GenItem>(
getActivity(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1,
LibHome.ITEMS
)
);
LibHome.java:
package com.example.prac2.lib;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class LibHome {
/**
* Create an Array
*/
public static List<GenItem> ITEMS = new ArrayList<GenItem>();
/**
* A map of sample (dummy) items, by ID.
*/
public static Map<String, GenItem> ITEM_MAP = new HashMap<String, GenItem>();
/**
* Add Items to the array
*/
static {
// Items!
addItem(new GenItem("1", "Title1", "File1"));
addItem(new GenItem("2", "Title2", "File2"));
addItem(new GenItem("2", "Title3", "File3"));
private static void addItem(GenItem item) {
ITEMS.add(item);
ITEM_MAP.put(item.id, item);
}
/**
* A dummy item representing a piece of content.
*/
public static class GenItem {
public String id;
public String content;
public String file;
public GenItem(String id, String content, String file) {
this.id = id;
this.content = content;
this.file = file;
}
@Override
public String toString() {
return content;
}
}
}