开发者

Unable to extract strings to strings.xml

开发者 https://www.devze.com 2023-04-02 08:53 出处:网络
hiho could someone tell me, how i should extract these strings? anything crashes the app. private String lv_arr[] = {

hiho could someone tell me, how i should extract these strings? anything crashes the app.

private String lv_arr[] = {

        "Weitere FAQs vom Autor dieser App",
        "Welche Wasserwerte sollte ich messen?",
        "Wie häufig sollte ich die Wasserwerte messen?"};

I tried:

private String lv_arr[] = {

        R.string.string_1,
        "Welche Wasserwerte sollte ich messen?",
        "Wie häufig sollte ich die Wasserwerte messen?"};

I tried:

private String lv_arr[] = {

        getString(R.string.string_1),
        "Welche Wasserwerte sollte ich messen?",
        "Wie häufig sollte ich die Wasserwerte m开发者_运维问答essen?"};

I tried:

private String lv_arr[] = {

        ""+getText(R.string.string_1)+"",
        "Welche Wasserwerte sollte ich messen?",
        "Wie häufig sollte ich die Wasserwerte messen?"};

Nothing is working. Crazy Thanks for Help Alex


You can declare a string array

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="string_array_name">
        <item>text_string</item>
    </string-array>
</resources>

http://developer.android.com/guide/topics/resources/string-resource.html#StringArray


Use

getResources().getString(R.string.mystring);


To use getString(int) you have to use it from an instance of the Context class. The Context class is the super-class of both Activity and Service. So make sure the class from which you are calling the getString(R.string.string_1) command is inside an activity that extends an Activity or a Service (basically any child of Context or Context itself).


Do this instead:

public class ... extends Activity {
    private String lv_arr[];

    public void onCreate(Bundle bundle) {
        lvArr = new String[] {
            getString(R.string.string_1),
            getString(R.string.string_2),
            getString(R.string.string_3), // etc
        };
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号