Есть ли метод, определяющий, нажата ли кнопка?
У меня есть цикл, мне в нем необходимо определить, нажата ли кнопка, и выполнить действие, если нажата.
Вот пример кода
for (int i = 0; i < LearnWordHelp.countCategories; i++) {
View page = ltInflater.inflate(R.layout.page_categories_learn_word, linLayout, false);
TextView tvLearnWortTextTitle = (TextView) page.findViewById(R.id.tvLearnWortTextTitle);
tvLearnWortTextTitle.setText(LearnWordHelp.masCategories[i]);
TextView tvNumberPopularWord = (TextView) page.findViewById(R.id.tvNumberPopularWord);
tvNumberPopularWord.setText(getResources().getString(R.string.number_word) + " " + LearnWordHelp.masCountWordAll[i]);
ImageView imgBackground = (ImageView) page.findViewById(R.id.imgBackground);
imgBackground.setImageDrawable(getResources().getDrawable(LearnWordHelp.masCategoriesCard[i]));
page.getLayoutParams().width = LayoutParams.MATCH_PARENT;
linLayout.addView(page);
CardView cvWordCategories = (CardView) page.findViewById(R.id.cvWordCategories);
cvWordCategories.setOnClickListener(this);
if (isPressed){
Intent intent = new Intent(LearnWord.this, LearnWordHelp.masClass[i]);
startActivity(intent);
}
}
}
@Override
public void onClick(View view) {
isPressed = true;
}
Я в цикле создаю карточки, и мне необходимо открыть новый экран при нажатии на кнопку с соответствующем классом.
Но такой код результата не дал, т.к. вначале цикл доходит до конца а потом вызывается метод.