I am using Relative Layout and many buttons in it with TextViews etc.I want to make all of them not clickable unless some event happens.
If Butterknife library is used, the views can be grouped and the functionality can be done on the group. Refer http://jakewharton.github.io/butterknife/,
@BindViews({ R.id.first_name, R.id.middle_name, R.id.last_name })
List nameViews;
The apply method allows you to act on all the views in a list at once.
ButterKnife.apply(nameViews, DISABLE);
ButterKnife.apply(nameViews, ENABLED, false);
Action and Setter interfaces allow specifying simple behavior.
static final ButterKnife.Action DISABLE = new ButterKnife.Action() {
@Override public void apply(View view, int index) {
view.setEnabled(false);
}
};
static final ButterKnife.Setter ENABLED = new ButterKnife.Setter() {
@Override public void set(View view, Boolean value, int index) {
view.setEnabled(value);
}
};
For eg., if the textviews are grouped, you could do
static final ButterKnife.Setter ENABLED = new ButterKnife.Setter() {
@Override public void set(TextView view, Boolean value, int index) {
view.setClickable(value);
view.setLongClickable(value);
if(value){
view.setTextColor(color);
} else {
view.setTextColor(color);
}
}
};