【发布时间】:2014-04-23 13:10:28
【问题描述】:
大家好,希望您能对此有所帮助,并感谢您查看我的 Q。 我需要更新的值
public static int hScoreGen1 = 0; (activity A)
来自另一个活动(活动 B)。
hScoreGen1 的值显示在活动 A 中的列表视图中
//Activity A
public void setList1(){
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("catGeneral","Level 1");
temp.put("score1", String.valueOf(hScoreGen1) + "/10");
listGeneral.add(temp);
}
和
//Activity A
adapter1 = new SimpleAdapter(
this,
listGeneral,
R.layout.list_highscore_row,
new String[] {"catGeneral","score1"},
new int[] {R.id.text1,R.id.text2}
);
和
//Activity A
public static SimpleAdapter adapter1;
这会改变价值
Activity B
if (totalCorrect > ScoreScreen.currentScoreCatValue){
HighScores.hScoreGen1 = totalCorrect;
HighScores.adapter1.notifyDataSetChanged();
}
有人告诉我,将适配器设为静态可能会导致泄漏。而对于侦听器,只需创建一个接口,在我要更新分数的 Activity 上实现它。在基本活动中设置此侦听器对象 [应用空检查] 并从第二个活动设置侦听器。听起来不错,但找不到这样的代码示例....如果您有任何想法,我们将不胜感激。
【问题讨论】:
标签: java android android-activity listener adaptor