Add a vowel at a time in a TextView

0

I have 5 buttons that emulate vowels, how does each button add a vowel at a time to a viewer, set to TextView ?

    
asked by anonymous 13.05.2018 / 12:31

1 answer

2
  • Display the 5 buttons and a TexTView.
  • Implement the View.OnClickListener class.
  • Set the event of this class for each button.
  • When triggering the event, use a switch command to manipulate the buttons.
    • With an auxiliary "Text" string, the vowels are concatenated. At the end of the event the TextView is set.
  • 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.

    13.05.2018 / 16:08