我正在与安卓合作,我想在AlertDialog按钮上做一个活动。我想要动态更改按钮上的文本,这是我的代码
AlertDialog.Builder alert = new AlertDialog.Builder(Soto_Betawi.this);
alert.setTitle("Payment");
alert.setMessage("Total Price : Rp. " + total);
final EditText input = new EditText(Soto_Betawi.this);
alert.setView(input);
alert.setPositiveButton("Change Due", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
cash = Integer.parseInt(input.getText().toString());
change = cash - total;
//I want to set a text from the operation above in a text
}
});
alert.setNegativeButton("Close", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
}
});
alert.setCancelable(true);
alert.create().show();发布于 2013-01-02 19:28:15
您可以使用带有对话主题的活动并创建自己的布局,而不是使用AlertDialog。这样,您就可以简单地使用
myButton.setText("your text");
发布于 2013-01-03 14:14:38
为您提供的另一个解决方案:
(AlertDialog)dialog.getButton(AlertDialog.BUTTON_POSITIVE)这应该会给你一个肯定的AlertDialog按钮
所以我的假设是
(AlertDialog)dialog.getButton(AlertDialog.BUTTON_POSITIVE).setText("Your Text");这应该是你的答案。
发布于 2013-01-02 19:38:24
通过以下方法创建和显示警报对话框:
public void showAlert(String txtPositiveButton) {
AlertDialog.Builder alert = new AlertDialog.Builder(Soto_Betawi.this);
alert.setTitle("Payment");
alert.setMessage("Total Price : Rp. " + total);
final EditText input = new EditText(Soto_Betawi.this);
alert.setView(input);
alert.setPositiveButton(txtPositiveButton, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
cash = Integer.parseInt(input.getText().toString());
change = cash - total;
//I want to set a text from the operation above in a text
}
});
alert.setNegativeButton("Close", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
}
});
alert.setCancelable(true);
alert.create().show();
}https://stackoverflow.com/questions/14121121
复制相似问题