实现“ onActivityResult”的扩展View类

时间:2020-08-18 10:05:13

标签: sharedpreferences extends onactivityresult

我正在为Android编写具有多个级别的游戏。 Mian Activity包含许多带有级别名称和玩家得分计数器的按钮。

每个按钮都是扩展View的CustomButton类的实例。 我将新按钮添加到Mian Activity中,如下所示:

CustomButton Level_1 = new CustomButton (this, "Level 1", level_1_score, flexboxlayout);

我有两个问题。

  1. 我想使用onactivityresult方法更新CustomButton类中按钮上的文本,以避免重复Mian Activity中的代码,但这是不可能的,因为CustomButton扩展了视图,而不是AppCompatActivity。
  2. 我不想复制共享首选项代码以将玩家的得分计数器保存在public static final String APP_PREFERENCES_LEVEL_SCORE = " level_1_score";

我要求您提供有关代码优化的建议。 Mian Activity contains many buttons with the level name and the player's score counter

0 个答案:

没有答案
相关问题