fragment的修改
public abstract class BaseFragment extends Fragment {
protected String TAG = BaseFragment.class.getSimpleName();
private Unbinder bind;
protected Context context;
private Toast mToast = null;
private static final int DISMISS = 1001;
private static final int SHOW = 1002;
private CustomProgressDialog progressDialog = null;
@SuppressLint("HandlerLeak")
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case SHOW:
if (progressDialog != null) {
progressDialog.setTouchAble((Boolean) msg.obj);
progressDialog.show();
}
break;
case DISMISS:
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
break;
default:
break;
}
}
};
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(getLayoutId(), container, false);
bind = ButterKnife.bind(this, inflate);
context = getActivity();
initData(savedInstanceState);
initListener();
mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
if (progressDialog == null) {
progressDialog = new CustomProgressDialog(context);
}
return inflate;
}
public abstract int getLayoutId();
public abstract void initData(Bundle savedInstanceState);
public abstract void initListener();
@Override
public void onResume() {
super.onResume();
if (mToast == null)
mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
if (progressDialog == null) {
progressDialog = new CustomProgressDialog(context);
}
}