我试图将一些参数传递给AlertDialog,此对话框大多显示了这两个参数(假设“foo”和“bar”参数),并且我使用showDialog(int id)
调用此对话框。在Activity类中有另一种方法,它采用Bundle
对象传递参数:showDialog(int id, Bundle args)
,但此方法仅适用于API 8或更高版本,我需要使用API 7.将参数传递给Android中的AlertDialog
在这里,我放了一些代码块使我所做的更容易。
在我的活动我创建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);
...
非常感谢您!