1

this is a game, and this game have a certain number of rounds, i want to click that button only the number of rounds the player selected.

this is my function, that saves the last 2 words from a input string, and shows on a textfield, i just want to run this function the number of "introndas"... i tried adding that last part of the code with "next.setEnable(False)"... but did nothing... Thanks guys

public void onClick (View v){

 edText1=findViewById(R.id.txtatual); int introndas = Integer.parseInt(nrondas); String aux=guardatexto(); String str[] = aux.split(" "); int lenghtofstr = str.length; if(lenghtofstr >=2){ lword=str[lenghtofstr-1]; pword=str[lenghtofstr-2]; String wordstoshow=pword+" "+ lword; ltextview.setText(wordstoshow); FinalTexto=FinalTexto+" " + aux;} edText1.setText(""); currentnumber++; if (currentnumber == introndas) next.setEnabled(false); else currentnumber = currentnumber + 1; } 

1 Answer 1

1

First create an integer field in your Activity (or Fragment) that will store the number of that button pressed. Say private int timesClicked = 0;.

Then in onClick() check if this counter reached that limit you want. It could be

int timesClicked = 0; public void onClick (View v){ if(++timesClicked <= roundsSelected){ // The limit is not reached yet... }else { // Player clicked button more times than the rounds selected. // Write logic here } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.