Skip to content

Instantly share code, notes, and snippets.

@unosk
Created April 12, 2015 18:59
Show Gist options
  • Save unosk/a457ca82bd8dcbda0dab to your computer and use it in GitHub Desktop.
Save unosk/a457ca82bd8dcbda0dab to your computer and use it in GitHub Desktop.
public abstract class BaseActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getClass().getAnnotation(InjectLayout.class).value());
ButterKnife.inject(this);
}
}
public abstract class BaseFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
int resource = getClass().getAnnotation(InjectLayout.class).value();
return LayoutInflater.from(getActivity()).inflate(resource, null);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.inject(this, view);
}
}
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface InjectLayout {
int value();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment