I have 5 buttons that emulate vowels, how does each button add a vowel at a time to a viewer, set to TextView
?
I have 5 buttons that emulate vowels, how does each button add a vowel at a time to a viewer, set to TextView
?
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);
}
This is the way I would do it today. There are other ways to accomplish this.