Twitter Facebook Delicious Digg Stumbleupon Favorites More

Friday 27 July 2018

read string value from resource

https://www.dev2qa.com/how-to-read-string-value-array-from-strings-xml-in-android/

<resources>

    <string name="button_show_selection">Show Selection</string>

    <string name="auto_complete_text_view_car">Input Favorite Car Name</string>

</resources>
String defaultInputText = getResources().getString(R.string.auto_complete_text_view_car);
  1. Define a string array in strings.xml use string-array xml element.
    <resources>
        <string name="button_show_selection">Show Selection</string>
    
        <string name="auto_complete_text_view_car">Input Favorite Car Name</string>
    
        <string-array name="car_array">
            <item>Audi</item>
            <item>BMW</item>
            <item>Benz</item>
            <item>Ford</item>
            <item>Toyota</item>
            <item>Tesla</item>
            <item>Honda</item>
            <item>Hyundai</item>
        </string-array>
    
    </resources>
  2. Read the string array in java source code. Please note car_array is just the string array name defined in strings.xml.
    String carArr[] = getResources().getStringArray(R.array.car_array);
Share:

0 comments:

Post a Comment

Search This Blog

Popular Posts

Pages

how to make crores from 1 lakh in stock markets in 1 year

how to make crores from 1 lakh in stock markets in 1 year

Blogger Tutorials

Blogger Templates

Sample Text

Copyright © ANDROID TUTORIAL CODE | Powered by Blogger
Design by SimpleWpThemes | Blogger Theme by NewBloggerThemes.com & Distributed By Protemplateslab