-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Please follow instructions below to begin using this library.
- Extends BaseApplication
First step to use this library is to Make your Application class extend BaseApplication.
public class SampleApplication extends BaseApplication {
@Override
public void onCreate() {
super.onCreate();
}
}
Don't forget change application name in your manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
...
<application
android:name="your.package.name.SampleApplication">
</application>
</manifest>
- Extends BaseActivity
In you want to utilize Binding feature, you must extends your Activity with BaseActivity.
BaseActivity itself extends from AppCompatActivity which use Android Support Fragment (appcompatv7).
Define content view by @ContentView
annotation. It will call setContentView
for you at Runtime.
Method onContentViewCreated
is called right before onCreate
finish. You you can treat this method same as onCreate
method. Do what you usually do in onCreate
in this method.
@ContentView(R.layout.activity_main)
public class MainActivity extends BaseActivity {
@ViewId(R.id.textview1)
private TextView textView1;
@Override
protected void onContentViewCreated() {
// Yo can safely access to textView1 in this method without call findViewById(). That's the magic
textView1.setText("Hello Elf");
}
}
- Extends BaseFragment
If you use Fragment, then you can extend your fragment with BaseFragment. And the other steps are same as when you use Activity.
@ContentView(R.layout.fragment_home)
public class HomeFragment extends BaseFragment {
@Override
protected void onContentViewCreated() {
// Treat this method as onCreateView() without inflate the layout
}
@OnClick(R.id.button1)
public void onButton1Clicked() {
// You can even bind button click listener without store it as variable.
}
}