Android - retrieve string array from resources

后端 未结 2 1690
清歌不尽
清歌不尽 2021-01-01 08:43

Below is the code that i made to retrieve the string array item:

String[] menuArray;

@Override
public void onCreate(Bundle savedInstanceState) 
{       
            


        
相关标签:
2条回答
  • 2021-01-01 09:31

    How to retrieve a string array from resources:

    array.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <string-array name="my_string_array">
            <item>one</item>
            <item>two</item>
            <item>three</item>
        </string-array>
    
    </resources>
    

    Code

    String[] stringArray = getResources().getStringArray(R.array.my_string_array);
    

    (The OP already had their question answered but based on the question title, other people may come here looking for this answer.)

    0 讨论(0)
  • 2021-01-01 09:46
    for(int i = 0;i<menuArray.length; i++) 
    {
        Button b = new Button(this);
        b.setText(menuArray[i]);
        ll.addView(b);
    }
    

    Delete the below statement

     try {
            x = count();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    

    and try to give layout height and width to all Layouts..

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