Your main problem here is that switch
statements require constant values as comparators, be it either a literal value e.g. 1
, "hello"
or a final
variable declared at class level. Android R.id
values have not been constant since API 14, as stated in that error message, so therefore cannot be used as part of a switch statement.
Your alternative would be to use if else
statements as they do not require constant values, like so:
if (v.getId() == R.id.something) {
// Do something
} else if (v.getId() == R.id.something_else) {
// Do something else
}
// Repeat however many times required
else {
// Default value
}