Morning!
I am very new to learning android and indeed Java, I am building an app to track rugby scores for a match between two teams. It works fine, but I'm annoyed by come of the code I have written. Basically, I am calling a different method for each onClick - which I guess is fine, but each of those methods calls 2 different display methods, which I am looking to streamline if I can.
Example:
public void try_home(View v) {
scoreHome += 5;
tryHome++;
displayForTeamA(scoreHome);
displayTryHome(tryHome);
}
And my reset is even worse:
public void reset(View v) {
displayForTeamA(scoreHome = 0);
displayForTeamB(scoreAway = 0);
displayTryHome(tryHome = 0);
displayTryAway(tryAway = 0);
displayConvertHome(convertHome = 0);
displayConvertAway(convertAway = 0);
displayFieldHome(fieldHome = 0);
displayFieldAway(fieldAway = 0);
displayPenHome(penHome = 0);
displayPenAway(penAway = 0);
}
So this is what I am trying to do, but obviously doesn't work because findViewById() want's an int.. am I on the right track, is there a way to do this?
public void display(int val, String textView) {
String viewID = "R.id." + textView;
TextView scoreView = (TextView) findViewById(viewID);
scoreView.setText(String.valueOf(val));
}
Hopefully I am making sense and my question is concise enough! Thank you in advance for any and all help