Move it to constants.
import ...; import ...; public class MainActivity extends Activity { public static final String[] texts = {"Математика","Музыка (Пение)","Изобразительное искусство (Рисование)","Английский язык","Казахский язык", "Немецкий язык","Китайский язык","История","География","Биология","Химия"}
Call by the name of the variable texts
. For example, to show the second element of the array in the Toast
message
Toast.makeText(this, texts[1], 0).show();
Ie, the name of the array of texts
and the index in square brackets (serial number minus one). For example, if you need the first element "Mathematics", then the index will be 0
, and so on.
And it’s better to make an array in res/values/array.xml
- be ready for localization (not all your users know Russian)
<string-array name="texts"> <item>Биография</item> <item>Русский Язык</item> <item>......</item> ... </string-array>
And in the Activity
code
String[] texts = getResources().getStringArray(R.array.texts);
Good luck!