Skip to content

Instantly share code, notes, and snippets.

@blazmag
Created September 14, 2014 23:06
Show Gist options
  • Save blazmag/bbfd5430ac4a9edff1cb to your computer and use it in GitHub Desktop.
Save blazmag/bbfd5430ac4a9edff1cb to your computer and use it in GitHub Desktop.
Fragment template with Butterknife + Otto init
public class ExampleFragment extends Fragment implements View.OnClickListener{
private Activity mActivity;
private Context mContext;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_example, container, false);
ButterKnife.inject(this,rootView);
BusProvider.getInstance().register(this);
Bundle arguments = getArguments();
return rootView;
}
@Override
public void onClick(View v) {
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
Log.i("Example", "OnAttach ExampleFragment called");
mActivity = activity;
mContext = activity.getApplicationContext();
}
@Override
public void onDetach() {
super.onDetach();
Log.i("Example", "OnDetach ExampleFragment called");
BusProvider.getInstance().unregister(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment