-1

I have created a interface with buttons, but i don't know how many buttons I need to create, so I have created them in java, with this code:

public void criaButton (String nome){

    TableLayout tl=(TableLayout)findViewById(R.id.tabBTALERT);    
    TableRow tr1 = new TableRow(this);
    tr1.setPadding(17, 15, 15, 5);
    final Button bt = new Button(this);
    bt.setText(nome);
    bt.setTextColor(Color.BLACK);
    bt.setBackgroundResource(R.drawable.botao);
    bt.setCompoundDrawablesWithIntrinsicBounds(R.drawable.envelope, 0, 0, 0);
    bt.setPadding(10, 20, 20, 20);
    bt.setId(id);
    tr1.addView(bt);
    tl.addView(tr1);
    bt.setOnClickListener( new View.OnClickListener() {
        public void onClick(View arg0) {

            idButton = bt.getId();
            nomeButton = (String) bt.getText();

            inicia ();
            Toast.makeText(Alerta.this, "Nome e ID : " + nomeButton + " " + idButton, Toast.LENGTH_SHORT).show();
        }
    });
}

with this method I can save the id and the name of every button I create. The problem is, these buttons have an image, and when I start another activity I have to change the image, if the message was read, not read, approved or rejected.

The question is, how can I give the id of the button to change the image and start again the activity with the changed image?? Is this possible?

dandan78
  • 13,328
  • 13
  • 64
  • 78
Soraia
  • 3
  • 3
  • One possibility is to store all of your `Button`s in a `List`. Then you can access them directly rather than retrieving them from the `Activity`. – Code-Apprentice Oct 05 '12 at 21:46

1 Answers1

0

Save the button ids in an array and then find the buttons by their ids and change their image to the desired one.

slybloty
  • 6,346
  • 6
  • 49
  • 70
  • thank you dandan78. Tell me please, is possible to write ids across Java temporarily in R class? thank you – Soraia Sep 07 '12 at 13:42
  • You can store the ids in a global array or pass them throw intents. http://stackoverflow.com/q/2091465/935627 – slybloty Sep 07 '12 at 13:46
  • thank you slybloty. I solved my problem with intents. Thank you for your help – Soraia Oct 07 '12 at 09:06