-1

我已经创建了一个带有按钮的界面,但是我不知道需要创建多少个按钮,所以我在 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 来更改图像并使用更改后的图像重新开始活动?这可能吗?

4

1 回答 1

0

将按钮 id 保存在一个数组中,然后通过它们的 id 找到按钮并将它们的图像更改为所需的图像。

于 2012-09-07T12:23:59.530 回答