Let's step back and look what's going on here:
- you have an instance variable (Button aBtn)
- you are referencing this instance variable in an inner class (new OnFocusChangeListener(){...})
Now, what's important to remember here is that the inner class's methods will be called at an undefined later date. So the methods contained in it is separate from the current flow of execution. Now imagine the following code:
for(Button aBtn : menu_Buttons)
{
aBtn.setOnFocusChangeListener(new OnFocusChangeListener(){
@Override
public void onFocusChange(View arg0, boolean changed) {
Log.i("LC", "focus changed");
if(changed)
{
aBtn.setTextColor(Color.parseColor("#FFFFFF"));
Log.i("LC", "true");
}
else
{
aBtn.setTextColor(Color.parseColor("#CD6839"));
Log.i("LC", "false");
}
}
});
if(someCondition) {
aBtn = someOtherButton;
}
}
In this case aBtn is changed, so which Button instance should the inner class be using when one of its method is called? No matter which one the compiler chooses, it bound to produce ambiguity to the programmer, which in turn would easily become a source of subtle and hard to trace bug.
By forcing final on an instance variable being referenced in an inner class, the compiler removed this ambiguity and makes coding correct programs easier.