我希望在对话框片段被关闭后 activity 到 refresh/redraw ..我怎样才能做到这一点?

I want the activity to refresh/redraw after dialog fragment is dismissed.. How can I achieve that?

初看起来是这样的:

这是按下 "edit" 时弹出的对话框片段,我希望在关闭对话框片段后在 activity 中看到更改。

public Dialog onCreateDialog(Bundle savedInstanceState) {
        final View view = getActivity().getLayoutInflater().inflate(R.layout.edit_profile_dialog, new LinearLayout(getActivity()), false);
        editProfile = (EditText) view.findViewById(R.id.changeProfile);
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        setupProgressDialog();
/*get value from Bundle*/
        String editValue = getArguments().getString("value", "");
        editProfile.setText(editValue);
        String title = getArguments().getString("title", "");
        builder.setTitle(title);
        builder.setView(view);
        builder.setCancelable(false);
        builder.setPositiveButton("Ok!", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
/*edit the value in shared preference*/
                sharedPref = getActivity().getSharedPreferences(getString(R.string.sharedPref), 0);
                editor = sharedPref.edit();
                editor.putString(getArguments().getString("saved", ""), editProfile.getText().toString());
                editor.apply();
               ID= sharedPref.getString("id", null);
                access_token=sharedPref.getString("token",null);
//Start of AsyncTask after this

在对话框的 onClickListener 中,您应该能够使布局无效并强制重绘/刷新

检查这个:How to force an entire layout View refresh?

如果您只需要更新用户从对话框输入的数据,则不必重绘整个布局。

您只能将用户名设置为相关的文本视图并关闭对话框片段。

TextView yourNameTextView = (TextView)findViewById(R.id.your_textview);

public void setNameToTextView(String name){
    yourNameTextView.setText(name);
}

当用户点击“确定”按钮时,您可以调用:

((YourActivity)getActivity).setText(input);

祝你好运。

感谢所有试图帮助我的人 out.I 认为我通过这样做得到了答案: 在我的 DialogFragment

public class DialogFragmentEditProfile extends DialogFragment {
...
/*Initialize Parent Activity*/
private ChangeProfileActivity cp;
/*Override onAttachMethod */
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
        cp = (ChangeProfileActivity) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString() + " must implement FeedbackListener");
        }
    }
/*create a method to recreate the parent activity*/
public void onButtonPushed(View view) {
cp.recreate();
    }

然后在DialogFragment中使用AsyncTask的onPostExecute()方法

  protected void onPostExecute(String result) {
            super.onPostExecute(result);
...
/*Recreate activity after successful update by calling the onButtonPushed() method*/
 onButtonPushed(getView());
}

}