This is a question for a generic problem with Android developing I would like to solve. Sometimes you have multiple buttons/text views etc that all need almost the same listener attached. The only difference being that each button/view is associated with a different field variable. Therefore the listener for each of the UI elements all have the exact same code except for which field variables are accessed/changed.
A horrible way of accomplishing this is to just make a lot of code duplication so you copy the code for the listener for each of the buttons and only changing the needed variables but this is obviously horrendous solution.
I tried to make a listener creator method that returned an anonymous listener class but could not figure out how to pass the relevant field variables as arguments to the creator method such that the anonymous listeners could use them.
How can this problem be solved in a good way?