(Java, Android) Button - Set Click's limit

0

Well, can someone tell me how to set a limit for the number of clicks on a button, and when I reach that limit, will I prevent the button from being clicked again?

Here it is:

 public void N1(View v) {
    EditText editTextView = (EditText) findViewById(R.id.editTextView);
    TextView tvN1 = (TextView) findViewById(R.id.textViewNumero1);
    editTextView.append(tvN1.getText().toString());}

This button functions as a key on a keyboard, when clicked it shows the character in editText. I wanted to first push the button before passing the next phase but prevent the button from being clicked more than once ...

Thanks if you can help me

    
asked by anonymous 30.07.2017 / 14:08

2 answers

3

Yes, just use the property setEnabled (false);

final Button btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        btn.setEnabled(false);
    }
});
    
30.07.2017 / 14:19
2

This can help you here

int quantidade_clicks = 0;
int vezes_click = 5;

public void N1(View v) {
    if(this.quantidade_clicks<=this.vezes_click){
        EditText editTextView = (EditText) findViewById(R.id.editTextView);
        TextView tvN1 = (TextView) findViewById(R.id.textViewNumero1);
        editTextView.append(tvN1.getText().toString());
        this.quantidade_clicks++;
        return;
    }
    Toast.makeText(this,"você não pode clicar mais de "+String.valueOf(this.vezes_click)+ "vezes!",10).show();
}
    
30.07.2017 / 20:59