我试图将一些参数传递给 AlertDialog,这个对话框最显示这两个参数(假设“foo”和“bar”参数),我正在使用showDialog(int id)
. Activity 类中还有另一种方法,它需要一个Bundle
对象来传递参数:showDialog(int id, Bundle args)
,但是这个方法只适用于 API 8 或更高版本,我需要使用 API 7。
在这里,我放了一些代码块,以使我正在做的事情更容易。
在我的活动中,我像这样创建 AlertDialog:
protected Dialog onCreateDialog(int id) {
final LayoutInflater factory = LayoutInflater.from(this);
switch(id) {
case DIALOG_ID:
final View view = factory.inflate(R.layout.dialog_layout, null);
final TextView fooValue = (TextView)view.findViewById(R.id.foo_label);
final TextView barValue = (TextView)view.findViewById(R.id.foo_label);
//fooLabel.setText("HERE MUST BE FOO PARAMETER VALUE");
//barLabel.setText("HERE MUST BE BAR PARAMETER VALUE");
return new AlertDialog.Builder(this).
setIcon(R.drawable.icon).
setTitle(R.string.app_name).
setView(view).
setPositiveButton(R.string.close, null).
create();
...
在其他部分,我称这个对话框为:
// THESE PARAMETERS MUST BE PASSED TO DIALOG
int foo = result.getInt("foo");
String bar = result.getString("bar");
showDialog(DIALOG_ID);
...
非常感谢!