-1
I’d like a little support from you... I’m trying to add a button to subtract and include the amount of items...
Look at my code... I’ve tried some ways, but without success. It has to be through Edittext
package com.example.trabalhohomecompras;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class Linha extends AppCompatActivity {
int numero = 0;
//private Button btnMais1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.linha);
Button btnMais1 = findViewById(R.id.btnMais1);
btnMais1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
numero = numero + 1; // adiciona +1 na váriavel numero
TextView t = (TextView) findViewById(R.id.textView_teste);
t.setText(String.valueOf(numero));
System.out.print(numero);
//TextView.setText(Integer.parseInt(String.valueOf(numero))); // coloca o valor na textview
//EditText simpleEditText = findViewById(R.id.edit_cont);
//System.out.println(numero);
//simpleEditText.setText(Integer.parseInt(String.valueOf(numero)));
//simpleEditText.setText(numero);
}
});
}
}
By doing this you guided me there returns that I must create a Gett for the variable t.setText
– user228750
t. setText(converterNumero); In this part of the code it states that you must "Extract Method" ai of the two options of making Gett out of onClik or inside it.
– user228750