Solution :
What you have here is the non-local variable i.e. you are accessing the local variable in a method of an anonymous class.
Local variables of your method are kept on a stack and lost as soon as your method ends, but even after your method ends, the local inner class object is still very much alive on the heap and it will need to access your variable here, when the action is performed.
I want to suggest two workarounds : Either you make your own class which implementsthe actionlistenner
and takes the constructor argument, and your variable and keeps it as the class attribute. So you should only access your variable within your same object.
Or just qualify the copy of your variable final
to access it in your inner scope as this error suggests to make it the constant:
This method would suit your case since you are not trying to modify your value of the variable.