Skip to content

Instantly share code, notes, and snippets.

@amendezcabrera
amendezcabrera / GetRandomPhrase.java
Created October 27, 2016 18:26 — forked from dolphinziyo/GetRandomPhrase.java
Return a random phrase from the strings.xml file starting by the required string ID
public void initializePhrases() {
Field[] fields = R.string.class.getFields();
loadingPhrasesList = new ArrayList<>();
String requiredIdStart = "loading_window_message_"; // Required string ID. In strings.xml file, the ID of the string must be "loading_window_message_" plus a number from 0 to inifinite (not so long :)
for (int i = 0; i < fields.length; i++) {
try {
String stringIdStart = fields[i].getName().substring(0, idStartText.length());
if (stringIdStart.equals(requiredIdStart)) {
loadingPhrasesList.add(fields[i].getName());
}