0
I have 5 buttons that emulate vowels, as each button adds one vowel at a time to a display, defined as TextView
?
0
I have 5 buttons that emulate vowels, as each button adds one vowel at a time to a display, defined as TextView
?
2
private Button btnA, btnE, btnI, btnO, btnU;
private TextView textView;
private String Texto="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.texto);
btnA = (Button) findViewById(R.id.btnA);
btnE = (Button) findViewById(R.id.btnE);
btnI = (Button) findViewById(R.id.btnI);
btnO = (Button) findViewById(R.id.btnO);
btnU = (Button) findViewById(R.id.btnU);
btnA.setOnClickListener(this);
btnE.setOnClickListener(this);
btnI.setOnClickListener(this);
btnO.setOnClickListener(this);
btnU.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.btnA:
Texto += "A";
break;
case R.id.btnE:
Texto += "E";
break;
case R.id.btnI:
Texto += "I";
break;
case R.id.btnO:
Texto += "O";
break;
case R.id.btnU:
Texto += "U";
break;
}
textView.setText(Texto);
}
That’s the way I would do it now. There are other ways to do it.
Browser other questions tagged java android
You are not signed in. Login or sign up in order to post.
Each time you press the key, for example "A" button, you concatenate the contents of the textview + "A", and you will be the textview again. Remembering that if the textview is empty, it can crash, so check before with the length.
– rbz
"will be" = "arrow"
– Piovezan