What's the problem?
Fragment transactions are asynchronous so in your code the fragment's dialog will not be available until the code/method in which you have the show()
call will return. Try using getSupportFragmentManager().executePendingTransaction()
after the show()
call or, much better, change your current code so the setProgress()
and setMsg()
store the values passed in(and update the views if they are available) followed by using those values when you create the dialog in the onCreateDialog()
callback.
Edit:
public class DialogFragmentProgress extends DialogFragment {
final static String DTAG = "FileCmd";
private String mMsg;
private int mCurProgress = -1;
public void setMsg(String msg) {
mMsg = msg;
// if we also have the view available update it
if (pb != null){
//... current code
}
public void setProgress(int progress){
mCurProgress = progress;
// if we also have the view available update it
if (pb != null){
// ... current code
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// current code...
// if mMsg and mCurProgress are valid it means they were set before the fragment's dialog
// was created so we need to use them at this moment
if (mMsg != null) {
// we have a valid message so use it at this moment to set the text
tv.setText(mMsg);
}
if (mCurProgress != -1) {
// we have a valid progress so use it at this moment to set the progress
pb.setProgress(mCurProgress);
}
return builder.create();
}