Hello. I decided to make a simple application for "learning" English. I am implementing a card system now (i.e. I press a button, a word pops up, I press again - again a new word). But my problem is that when you press a button, the word appears, but it does it once. I clicked once, one word showed, and that’s the end. How many press do not press - violet. Tell me what to do in this situation? PS I apologize for govnokod. Tried a lot of things and nothing helped (

public class Word extends AppCompatActivity { TextView MainTextView; TextView detailed; public int levelint = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_word); MainTextView = findViewById(R.id.TextWordTable); detailed = findViewById(R.id.detailed); } public class WordList { String[] level1 = {"an Apple","a House","a Man","an Apple","a House","a Man","a Xui"}; String[] leveldetal = {"Яблоко","Дом","Мужыг"}; String[] level2 = {"a Boy","A girl","level 3"}; String[] level3 = {"ss","level 2","level 3"}; int step = 0; } public void onClick(View v) { WordList allWord = new WordList(); //for (int i = 0; i < allWord.level1.length; i++) { //MainTextView.setText(allWord.level1[i]); //detailed.setText(allWord.leveldetal[i]); if (levelint == 0) { String disp = new String(allWord.level1[allWord.step]); MainTextView.setText(disp.toString()); allWord.step++; if (allWord.step == 10) levelint++; allWord.step = 0; } else if (levelint == 1) { MainTextView.setText(allWord.level2[allWord.step]); allWord.step++; if (allWord.step == 10) levelint++; allWord.step = 0; } } } 
  • You have WordList allWord = new WordList (); limited to onClick (..) method area. Those. an object is created, displays the text of 1 card, makes step = 1, and upon completion of the onClick method, the object is deleted. The next time you press the button, everything repeats again. Take out the WordList allWord ad from the method, make it global, and everything will work well - MiMEKiZ
  • I moved it to the beginning of the class and nothing has changed :( - mrpl_ivan
  • if (allWord.step == 10) levelint ++; allWord.step = 0; Shouldn't these two actions be under {} together? Without combining them into a block, after each pressing the button, the step becomes equal to 0. Always. The if action does not apply to it in this case - MiMEKiZ
  • here you are big-eyed. earned) thanks a lot) - mrpl_ivan

0