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?