public final class ButterKnife
extends java.lang.Object
Finding views from your activity is as easy as:
public class ExampleActivity extends Activity {
@BindView(R.id.title) EditText titleView;
@BindView(R.id.subtitle) EditText subtitleView;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.example_activity);
ButterKnife.bind(this);
}
}
Binding can be performed directly on an activity, a
view, or a dialog. Alternate objects to
bind can be specified along with an activity,
view, or
dialog.
Group multiple views together into a List
or array.
@BindView({R.id.first_name, R.id.middle_name, R.id.last_name})
List nameViews;
To bind listeners to your views you can annotate your methods:
@OnClick(R.id.submit) void onSubmit() {
// React to button click.
}
Any number of parameters from the listener may be used on the method.
@OnItemClick(R.id.tweet_list) void onTweetClicked(int position) {
// React to tweet click.
}
Be default, views are required to be present in the layout for both field and method bindings.
If a view is optional add a @Nullable
annotation for fields (such as the one in the
support-annotations library)
or the @Optional
annotation for methods.
@Nullable @BindView(R.id.title) TextView subtitleView;
Resources can also be bound to fields to simplify programmatically working with views:
@BindBool(R.bool.is_tablet) boolean isTablet;
@BindInt(R.integer.columns) int columns;
@BindColor(R.color.error_red) int errorRed;
Modifier and Type | Method and Description |
---|---|
static Unbinder |
bind(android.app.Activity target)
BindView annotated fields and methods in the specified
Activity . |
static Unbinder |
bind(android.app.Dialog target)
BindView annotated fields and methods in the specified
Dialog . |
static Unbinder |
bind(java.lang.Object target,
android.app.Activity source)
BindView annotated fields and methods in the specified
target using the source
Activity as the view root. |
static Unbinder |
bind(java.lang.Object target,
android.app.Dialog source)
BindView annotated fields and methods in the specified
target using the source
Dialog as the view root. |
static Unbinder |
bind(java.lang.Object target,
android.view.View source)
BindView annotated fields and methods in the specified
target using the source
View as the view root. |
static Unbinder |
bind(android.view.View target)
BindView annotated fields and methods in the specified
View . |
static void |
setDebug(boolean debug)
Control whether debug logging is enabled.
|
public static void setDebug(boolean debug)
public static Unbinder bind(android.app.Activity target)
Activity
. The current content
view is used as the view root.target
- Target activity for view binding.public static Unbinder bind(android.view.View target)
View
. The view and its children
are used as the view root.target
- Target view for view binding.public static Unbinder bind(android.app.Dialog target)
Dialog
. The current content
view is used as the view root.target
- Target dialog for view binding.public static Unbinder bind(java.lang.Object target, android.app.Activity source)
target
using the source
Activity
as the view root.target
- Target class for view binding.source
- Activity on which IDs will be looked up.public static Unbinder bind(java.lang.Object target, android.app.Dialog source)
target
using the source
Dialog
as the view root.target
- Target class for view binding.source
- Dialog on which IDs will be looked up.public static Unbinder bind(java.lang.Object target, android.view.View source)
target
using the source
View
as the view root.target
- Target class for view binding.source
- View root on which IDs will be looked up.