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

Nishan Khadka picture Nishan Khadka · Jun 14, 2016 · Viewed 9.3k times · Source

This is how it looks at first:

The image description of the first image

This is the dialog fragment that pops when "edit" is pressed and I want The change to be seen in the activity after the dialog fragment is dismissed. The image description of the second image

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

Answer

savepopulation picture savepopulation · Jun 14, 2016

If you only need to update the data which user inputs from your dialog you do not have to redraw whole layout.

You can only set the user name to the related textview and dismiss dialog fragment.

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

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

And when user clicks to Ok button you can call:

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

Good luck.