Android 我希望活动在对话框片段被取消后刷新/重画。。我怎样才能做到这一点?

Android 我希望活动在对话框片段被取消后刷新/重画。。我怎样才能做到这一点?,android,android-dialogfragment,redraw,Android,Android Dialogfragment,Redraw,一开始是这样的: 这是当按下“编辑”时弹出的对话框片段,我希望在对话框片段被取消后在活动中看到更改。 在对话框的onClickListener中,您应该能够使布局无效并强制重画/刷新 选中此项:如果只需要更新用户从对话框输入的数据,则无需重新绘制整个布局 您只能将用户名设置为相关的textview和Disclose对话框片段 TextView yourNameTextView = (TextView)findViewById(R.id.your_textview); public void

一开始是这样的:

这是当按下“编辑”时弹出的对话框片段,我希望在对话框片段被取消后在活动中看到更改。


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


选中此项:

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

您只能将用户名设置为相关的textview和Disclose对话框片段

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

public void setNameToTextView(String name){
    yourNameTextView.setText(name);
}
当用户单击“确定”按钮时,您可以调用:

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

祝你好运。

感谢所有试图帮助我的人。我想我是这样做的: 在我的对话片段中

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();
    }
  protected void onPostExecute(String result) {
            super.onPostExecute(result);
...
/*Recreate activity after successful update by calling the onButtonPushed() method*/
 onButtonPushed(getView());
}
然后在DialogFragment中使用AsyncTask的onPostExecute()方法

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();
    }
  protected void onPostExecute(String result) {
            super.onPostExecute(result);
...
/*Recreate activity after successful update by calling the onButtonPushed() method*/
 onButtonPushed(getView());
}

}

分享一些代码。。!!我的意思是你的对话的。。!!Try overriding
onResume
的可能重复对于您的片段来说,直接处理一个特定活动不是一个好模式。对于这一点,我更喜欢这样使用合同模式:你们是对的,但我认为这是一个快速有效的解决问题的方法。不是我所接受的最好的