Reputation: 37
I don't get the correct index. Can anyone tell me why? I expect 0 as index, not -1.
int[] id = {R.id.buKeyPadNum1, ...} **(EDIT)**
int index = Arrays.asList(id).indexOf(v.getId());
Log.i("onClick", "v.getId "+ String.valueOf(v.getId())+" ButtonId "+String.valueOf(id[0])
+" Index "+String.valueOf(index));
LogCat: 09-25 08:11:32.039: I/onClick(1680): v.getId 2131296337 ButtonId 2131296337 Index -1
Upvotes: 0
Views: 88
Reputation: 4248
Arrays.asList(id)
returns a List<long[]>
. indexOf()
only works on Long[]
objects. See this answer.
Try using the Long[]
type for id
.
Upvotes: 1
Reputation: 4014
Consider such code:
int ix = Arrays.asList(new int[]{1,2}).indexOf(1);
// result: -1
int ix = Arrays.asList(new Integer[]{1,2}).indexOf(1);
// result: 0 (found)
Probably your array contains elements with different type from indexOf argument.
Upvotes: 1