这是我正在尝试做的事情: - 从 SharedPreferences 对象(用户#,名称)中检索键值对映射 - 将这些键值对写入 ArrayList 以便我可以 - 使用它们填充 ListView每行都包含键和值,如下所示:
用户 1 - 乔 R。
用户 2 - Frank B.
ETC
更新:所以在对 SimpleAdapter 类进行了长时间的研究,并与一些更聪明、更有知识的人交谈之后——我比以前更接近了……但仍然没有走到那一步。
这就是我现在所拥有的:
public class LogHistory extends ListActivity {
static final ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
private static final String KEY = null;
private static final String VALUE = null;
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.log_history);
SharedPreferences logPrefs = getSharedPreferences(LoginField.PREFSNAME, 0);
Map<String, ?> logMap = logPrefs.getAll();
for (Map.Entry<String, ?> e : logMap.entrySet()) {
HashMap<String, String> row = new HashMap<String, String>();
String mKey = e.getKey();
String mValue = (String) e.getValue();
row.put(KEY, mKey);
row.put(VALUE, mValue);
list.add(row);
// FOR DEBUGGING PURPOSES
makeToast(mKey);
makeToast(mValue);
}
SimpleAdapter adapter = new SimpleAdapter(
this,
list,
R.layout.list_item,
new String[] { KEY, VALUE },
new int[] {R.id.item1, R.id.item2}
);
setListAdapter(adapter);
这种工作 - 但只有一半......结果我得到的是两列中的 VALUES 列表......
但是 makeToast 函数为 KEY 和 VALUE 返回了正确的值 - 所以问题一定出在 SimpleAdapter 方法中是吗?
帮助会很棒 - 今晚要交作业!:-0