This repository was archived by the owner on Jun 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Content View Binding
Steven Lewi edited this page Apr 9, 2015
·
1 revision
@ContentView can be used to automatically set content view of Activities, Fragments and Dialogs. Just put this annotation on top of your Activity/Fragment/Dialog class and framework will do the job for you (inflating/applying the layout).
See this example below.
public class MainActivity extends Activity {
@Override
protected void onCreate() {
setContentView(R.layout.activity_main);
}
}@ContentView(R.layout.activity_main)
public class MainActivity extends BaseActivity {
@Override
protected void onContentViewCreated() {
}
}public class MainFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}@ContentView(R.layout.activity_main)
public class MainFragment extends BaseFragment {
@Override
protected void onContentViewCreated() {
}
}public class CustomDialog extends Dialog {
public CustomDialog(Context context) {
super(context);
initLayout();
}
public CustomDialog(Context context, int theme) {
super(context, theme);
initLayout();
}
protected CustomDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
initLayout();
}
private void initLayout() {
setContentView(R.layout.dialog1);
}
}@ContentView(R.layout.dialog1)
public class CustomDialog extends BaseDialog {
public CustomDialog(Context context) {
super(context);
}
public CustomDialog(Context context, int theme) {
super(context, theme);
}
protected CustomDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
}
@Override
protected void onContentViewCreated() {
}
}