Dialog Window和activity是完全不同的东西。
可以从它的对话框中刷新第一个活动。您可以使用界面来完成。
这是简单的解决方案。在您的第一个活动中实现了一个接口名称IRefreshInteface。它的定义如下:
public interface IRefreshInteface(){
public void doRefreshValue(String commandValue);
}
现在,如果您在 Activity 中实现 IRefreshInteface,您将获得方法 doRefreshValue(String commandValue) 并在此处编写刷新代码。
@Override
void doRefreshValue(String commandValue){
// Write refresh code here
}
现在在您的对话框中,您有 Activity 的上下文。使用该上下文对象,您可以轻松调用此doRefreshValue(String commandValue) 方法。这是示例代码:
public AlertDialog displayMessage(Context context, String title, String message){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setMessage(message);
LayoutInflater inflater = LayoutInflater.from(context);
final View v = inflater.inflate(R.layout.custom_view, null);
builder.setView(v);
shipText = (EditText)v.findViewById(R.id.shipNameEditText);
scientistNameText = (EditText)v.findViewById(R.id.scientistEditText);
scientistEmailText = (EditText)v.findViewById(R.id.emailEditText);
volumeText = (EditText)v.findViewById(R.id.volumeEditText);
colourText = (EditText)v.findViewById(R.id.colourEditText);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((IRefreshInteface) context).doRefreshValue("YOUR_COMMAND");
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog= builder.create();
dialog.show();
Button tb = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
tb.setOnClickListener(new CustomListener(dialog));
return dialog;
}
这里,将Activity的Context传递给displayMessage()方法,并使用这种方式调用Activity方法doRefreshValue:
((IRefreshInteface) context).doRefreshValue("YOUR_COMMAND");
更多信息请访问here和here
希望这能解决您的问题。抱歉英语不好:)