My question is actually not a problem with code but rather how to accomplish it in the most efficient manner: both in terms of application resources and time to create while attempting to stay true to OOP. Please feel free to point out where incongruence exists.
Objective:
- User will be presented with a number of rows (assume 30)
- Each row will be made up of 3 TextViews (TV for brevity) and 1 Button that sum values together into a total number
- TV1 will sum TV2 & 3
- TV2 will based on a value in a SQLiteDB (which I have already set up) who's values will be based on 1 of 6 values calculated in another fragment
- TV3 will be initialized at 0
- Button will add 1 to TV3 onClick
Current Planned Implementation:
- setOnClickListeners for the 30 buttons
- onClick for each button will set a static int to a number based on what button was pressed
- onClick would then call method addOne
- addOne will use a switch to add one to the appropriate TV3 and TV3.setText based on the static int value
- Finally the appropriate row's T2 & 3 would be added together and TV1.setText
Needless to say, this looks to be very tedious to write and am wondering if this is the only/optimal way to accomplish this or is there a better alternative?
You can implement it through a list adapter. In its getView() function, get hold of the button and set onClick listener function. Inside the function you can do all your calculation and set the result to the corresponding TextView.