Reputation: 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;
}
}
Upvotes: -1
Views: 1078
Reputation: 86
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);
Upvotes: 0
Reputation: 185
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;
}
Upvotes: 1