-1

i have been trying to use this code for my application. Im trying to call this class in strings.xml but i couldn't figure it out. How can i call the class in strings.xml?

public class Sorular {

    public String Sorular[] = {
            "When did Facebook came out?",
            "Who is a Google Developer?",
            "Whitch one is the first Smartphone?"
    };

    public String Secenekler[][] = {
            {"2002", "2003", "2004"},
            {"Bill Gates", "Steve Jobs", "Larry Page"},
            {"Iphone", "Samsung", "Nokia"}
    };

    public String DogruCevap[] = {
            "2004",
            "Larry Page",
            "Iphone"
    };

    public String getQuestion ( int a){
        String soru = Sorular[a];
        return soru;
    }

    public String getchoice1 ( int a){
        String secenek = Secenekler[a][0];
        return secenek;
    }

    public String getchoice2 ( int a){
        String secenek = Secenekler[a][1];
        return secenek;
    }

    public String getchoice3 ( int a){
        String secenek = Secenekler[a][2];
        return secenek;
    }

    public String getCorrectAnswer ( int a){
        String cevap = DogruCevap[a];
        return cevap;
    }
}

2 Answers 2

1

Here you find how to add array in string.xml

<string-array name="Sorular">
    <item>When did Facebook came out?</item>
    <item>Who is a Google Developer?</item>
    <item>Whitch one is the first Smartphone?</item>
</string-array>

Here you can find how to call from java

public String getQuestion (Context context, int a){
    String soru = context.getResources().getStringArray(R.array.Sorular)[a];
    return soru;
}
Sign up to request clarification or add additional context in comments.

Comments

0

You need to put all your strings inside string.xml file, and then reference them from your code with the following call:

context.getResources().getString(R.string.word);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.