【发布时间】:2014-04-22 12:27:15
【问题描述】:
大家好,感谢您的关注,希望您能找到答案……我正在尝试更新高分屏幕。 这是我的适配器
SimpleAdapter adapter1 = new SimpleAdapter(
this,
listGeneral,
R.layout.list_highscore_row,
new String[] {"catGeneral","score1"},
new int[] {R.id.text1,R.id.text2}
);
这填满了我的清单
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("catGeneral","Level 1");
temp.put("score1", String.valueOf(hScoreGen1) + "/10");
listGeneral.add(temp);
我想更改hScoreGen1 的值,如果它低于新分数...
到目前为止,我在另一个应该改变 hScoreGen1 值的活动中有这个
if (totalCorrect > ScoreScreen.currentScoreCatValue){ //currentScoreCatValue is the orginal value of hScoreGen1
if (currentScoreCat == 1){ //currentScoreCat is set to 1 from another activity
HighScores.hScoreGen1 = totalCorrect;
我的问题似乎是列表视图没有显示更改的值,而是显示 onCreate 值...希望您能提供帮助 如果需要,我可以添加更多代码
【问题讨论】:
-
您必须刷新列表视图?通知数据集更改()。更多信息Here 还确保您从主 UI 线程调用它。
-
致电
notifyDataSetChanged() -
使用 notifydatachanged() 更新您的 HashMap 和 SimpleAdapter
-
不要让你的适配器静态,可能会发生泄漏。而是实现广播和接收器来实现这个,或者监听器。
-
@jitain 你能给我代码示例吗,我不知道如何从其他活动中调用适配器,而不是通过静态
标签: android listview android-activity