I'm building an Android application with a tabbed layout using Tabhost and Fragments.
In one of the tabs (fragment) I have a textview which displays the value of a String variable. This tab also has a button which calls a DialogFragment in which i can edit the value of said string, via an EditText box.
It all works as expected, except for one glitch: once the DialogFragment is dismissed and the tab gets focus again, the textview text doesn't refresh automatically. To make it refresh i need to change tab and get back.
Is there an instruction i can add so that when a DialogFragment is dismissed, its parent activity is reloaded/refreshed?
Thanks in advance.
EDIT: Still looking for a solution, couldnt figure out how to use DialogFragment.isdetached
To set a keyword, this can be done via the Handler mechanism.
I had a similar situation, displaying showing a DialogFragment from a Fragment, where the DialogFragment should report its' dismiss to the Fragment.
In your case you seem to use a (Fragment)Activity instead of Fragment, but i think that makes no difference here.
Steps
Code
public class YourActivity extends Activity {
...
public void someMethod() {
...
YourDialoagFragment yourDialoagFragment =
new YourDialoagFragment(new YourDialogFragmentDismissHandler());
yourDialoagFragment.show();
...
}
private class YourDialogFragmentDismissHandler extends Handler {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
// refresh your textview's here
}
}
...
}
public class YourDialoagFragment extends DialoagFragment {
...
Handler handler;
public YourDialoagFragment(Handler handler) {
this.handler = handler
}
...
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
handler.sendEmptyMessage(0);
}
...
}
I hope this helps!
Your problem is that dialogFragment's action affects the data or view of the previous fragment.And you want to refresh the previous fragment's data or view after dialogfragment's dismiss. But the previous dialogfragment's dismiss can't invoke the previous fragment's onCreateView()
or onCreate()
.
In this predicament, you can use Broadcast. When you refresh the previous fragment's data or view's data. You can send broadcast. Once the previous fragment receive the broadcast, the previous fragment can refresh now, not at the dismiss of the dialogfragment. I think this is a better solution especially in multithread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With