How to use getString() on static String before onCreate()?

前端 未结 5 1482
陌清茗
陌清茗 2020-12-17 10:09

I am trying to use getString() to get an String from resources to assign it to an String array before my activity is created:

private static fin         


        
5条回答
  •  独厮守ぢ
    2020-12-17 10:47

    Another approach could be to initialize the static array with resource identifiers (which are already available as opposed to the resources themselves).

    private static final int[] MenuNames = {
        R.string.LCMeterMenu,
        R.string.FrecMenu,
        ...
    };
    

    This way, you can defer the loading of resources to when they are actually available:

    String s = getResources().getString(MenuNames[i]);
    

提交回复
热议问题