problem filling string[] with string-array from strings.xml

后端 未结 3 804
别那么骄傲
别那么骄傲 2021-01-22 19:32

EDIT: woah ... somehow i replaced this question with another one i was asking, glad there is this rollback feature

this specific question deals with the

相关标签:
3条回答
  • 2021-01-22 20:10

    suggest not to define an array in advance, and used directly without defining a variable

    mAutoComplete.setAdapter (new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, getResources().getStringArray(R.array.OmskStreets)));
    

    and more..

    in Class

    private String[] mStreets = null;
    

    and in onCreate method

    mStreets = getResources().getStringArray(R.array.OmskStreets);
    
    0 讨论(0)
  • 2021-01-22 20:13

    Shouldn't define anything about UI before onCreate().

    Moreover, the following is a poor coding example, but it works.

    public void onCreate(Bundle icicle){
         super.onCreate(icicle);
    ...
    ...
    ...
         COUNTRIES  = getResources().getStringArray(R.array.COUNTRIES_ARRAY);
    
    0 讨论(0)
  • 2021-01-22 20:15

    i know this is poor coding, apologies in advance. so to fix this problem, i moved

    String[] impactsn;
    impactsn = getResources().getStringArray(R.array.impacts);
    

    to my main activity and made it static. now i refer to it within my Impacts class as (MainActivity).impactsn[]

    i know this is not how you are supposed to share objects between classes, but it seems to be the easiest way so far. this is yet another reason why i am regretting my decision to make all of my tabs seperate activities. if you have any suggestions or advice on how to fix this code without using static references or on reasons why all of my tabs should be the same activities, please chime in.

    0 讨论(0)
提交回复
热议问题