Skip to content

Instantly share code, notes, and snippets.

@mistrydarshan99
Forked from vaibhav-jani/BaseFragment.Java
Last active August 28, 2015 10:50
Show Gist options
  • Select an option

  • Save mistrydarshan99/f91ad5409f65c3b4064b to your computer and use it in GitHub Desktop.

Select an option

Save mistrydarshan99/f91ad5409f65c3b4064b to your computer and use it in GitHub Desktop.
/**
* Created by vaibhav.jani on 15-Jul-15.
*/
public abstract class BaseFragment extends Fragment {
protected View rootView;
protected HomeActivity activity;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(getContentView(), container, false);
initViews(rootView);
return rootView;
}
protected abstract int getContentView();
protected abstract void initViews(View rootView);
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.activity = (HomeActivity) activity;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
loadData();
}
protected abstract void loadData();
protected boolean finish(){
/*if(activity instanceof HomeActivity) {
HomeActivity homeActivity = (HomeActivity) activity;
homeActivity.popFragment();
}*/
activity.popFragment(true);
return true;
}
public void showProgressDialog(String title, String message) {
if(isAdded()){
activity.showProgressDialog(title, message);
}
}
public void dismissProgressDialog() {
if(isAdded()){
activity.dismissProgressDialog();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment