ボタン付きのインターフェイスを作成しましたが、作成する必要があるボタンの数がわからないため、Java で次のコードを使用して作成しました。
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();
}
});
}
このメソッドを使用すると、作成したすべてのボタンの ID と名前を保存できます。問題は、これらのボタンには画像があり、別のアクティビティを開始するときに、メッセージが既読、未読、承認、または拒否された場合に、画像を変更する必要があることです。
問題は、画像を変更し、変更された画像でアクティビティを再開するボタンの ID をどのように指定できるかということです。これは可能ですか?