Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to load string array value from string.xml in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 258
    Comment on it

    Using below code I have created a load string array value from string.xml. String is a simple resource using the value provided in the name attribute. So we can combine string resources with other simple resourecs in the xml file. Below code will clearly describe you how to load string arrayvalue from string.xml.

    Step(1)-Create a class-

    public class Test extends ListActivity {
      String[] presidents;
      public void onCreate(Bundle savedInstanceState) {
        ListView lstView = getListView();
        // lstView.setChoiceMode(0); 
        // lstView.setChoiceMode(1); 
        presidents = getResources().getStringArray(R.array.presidents_array);
        setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_checked, presidents));
      public void onListItemClick(ListView parent, View v, int position, long id) {
        parent.setItemChecked(position, parent.isItemChecked(position));
        Toast.makeText(this, "You have selected " + presidents[position],

    Step(2)-main.xml layout-

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android=""


    <?xml version="1.0" encoding="utf-8"?>
        <string name="hello">Hello World, MainActivity!</string>
        <string name="app_name">BasicViews5</string>
        <string-array name="presidents_array">
            <item>Big Data</item>

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: