androidAnnotations is a third-party framework that uses annotations to develop applications. Using androidannotations can greatly reduce the amount of code.
[Java]
Package com.example.androidannotations;
Import android.app.Activity;
Import Android.widget.TextView;
Import Com.googlecode.androidannotations.annotations.AfterViews;
Import com.googlecode.androidannotations.annotations.EActivity;
Import Com.googlecode.androidannotations.annotations.ViewById;
Eactivity annotations can be set to layout, equivalent to the Setconentview method
@EActivity (R.layout.activity_main)
public class Mainactivity extends Activity {
Viewbyid annotation function is the same as Findviewbyid, if the declared variable name is ID, you can omit the parameter, otherwise you should add the ID, such as Viewbyid (r.id.tv)
@ViewById
TextView TV;
The method defined by the Afterviews annotation is executed after the Setcontentview of the OnCreate method
@AfterViews
void Init ()
{
Tv.settext ("Asfsdf");
}
}
Package com.example.androidannotations;
Import android.app.Activity;
Import Android.widget.TextView;
Import Com.googlecode.androidannotations.annotations.AfterViews;
Import com.googlecode.androidannotations.annotations.EActivity;
Import Com.googlecode.androidannotations.annotations.ViewById;
Eactivity annotations can be set to layout, equivalent to the Setconentview method
@EActivity (R.layout.activity_main)
public class Mainactivity extends Activity {
Viewbyid annotation function is the same as Findviewbyid, if the declared variable name is ID, you can omit the parameter, otherwise you should add the ID, such as Viewbyid (r.id.tv)
@ViewById
TextView TV;
The method defined by the Afterviews annotation is executed after the Setcontentview of the OnCreate method
@AfterViews
void Init ()
{
Tv.settext ("Asfsdf");
}
}
How to use some common annotations:
@AfterInject defined methods are executed after the constructor method of the class is executed
@AfterTextChange defined method executes after the text property of the TextView and its subclasses is changed
@AfterViews defined methods are executed after Setcontentview
@Background defined methods are executed in the background thread
@BeforeTextChange defined methods are executed before the Text property of the TextView and its subclasses is changed
@Click Define Click Listeners
@EActivity enable annotations in activity
@EProvider enable annotations in ContentProvider
@EReceive enable annotations in Broadcastreceiver
@EService enable annotations in the service
@EView enable annotations in a child class of a custom view
@Fullscreen fullscreen
@NoTitle No title bar
Androidannotations using annotations to develop applications