更新另一个活动中的变量

时间:2014-04-22 12:27:16

标签: android listview android-activity

嘿大家都感谢您的期待并希望您找到答案...我试图更新一个高分屏幕。 这是我的适配器

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值...希望你能帮忙 我可以根据需要添加更多代码

1 个答案:

答案 0 :(得分:0)

更新你的适配器

    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;
                            HighScores.adapter1.notifydatachanged();