As part of teaching myself to code Android Apps, I am writing an App to keep track of some numbers for a Board Game. As my screenshot shows, I have several values, with minus/plus buttons. The Ship (implemented as a Ship Class) has 6 Values, and therefore 12 Buttons, and 6 TextViews.
As the Game progresses, the Numbers will change, and the User should be able to click the -/+ buttons to reflect this.
Initially, I wrote a separate onClickListener for each Button, updating the Ship Value, and setting the TextView to the new Ship Value.
I then decided to consolidate this into a single OnClickListener, attached to each Button, and a Switch/Case statement, with a case for each Button, that updated the clicked Ship Value, and then re-displayed the Values.
In another attempt to consolidate my code, I wrote a Class to implement a Number Picker (based upon this code: https://stackoverflow.com/a/56061379/3902474 )
The problem that I now have is that although the Number Picker can update the TextViews, I do not know how to get it to update the Ship Values.
The Number Picker does not have access to the Ship Class (and I would like to re-use it for several other types of values).
Is there a way of setting the Ship Values, using this Number Picker, while keeping the Number Picker generic enough to use for other Values/Classes?