So the problem I guess is that your public
method is called before onCreate
and etc. because after calling show
to your DialogFragment
it takes time to initialise the dialog, it's view and all variables. So the way you can handle this the right way in my opinion is just create a boolean
variable which you set before showing your DialogFragment
. Something like this :
public class RemoteProgressDialog extends DialogFragment {
private boolean mShowText = false; // default value
private TextView lockProgress;
public void setShowText(boolean showText){
this.mShowText = showText;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.remote_progress_dialog, null);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
// initialise your views here
lockProgress = (TextView) view.findViewById(R.id.lock_progress);
showLockProgress(mShowText);
}
public void showLockProgress(boolean show) {
lockProgress.setVisibility(show ? View.VISIBLE : View.GONE);
}
}
and you can do something like this before showing your Dialog
:
progressDialog.show(getFragmentManager(), REMOTE_PROGRESS_DIALOG);
progressDialog.setShowText(true);
So this way you won't get NullPointerException
and you can be sure that depending on the boolean
which you set, your TextView
in RemoteProgressDialog
will be hidden or visible when it is initialised.
Hope this helps!