Android: View.getTag/setTag and IllegalArgumentException

前端 未结 1 399
生来不讨喜
生来不讨喜 2021-02-13 00:28

Yes, I know you need a unique resource id when calling the version of these functions that requires a key, but I cannot for the life of me figure out how to create a resource id

1条回答
  •  不思量自难忘°
    2021-02-13 00:34

    From the Javadoc:

    The specified key should be an id declared in the resources of the application to ensure it is unique.

    So you can't just make up values and place them in a local variable.

    Every resource you create whether it's a string (R.string.*), or a layout (R.layout.*) or an individual View (R.id.*) can have an ID. This is something you must be doing already.

    If you do need to store multiple objects against a single View, then you need to use the R.id variant as a key, like someView.setKey(R.id.my_key_1, someObject).

    0 讨论(0)
提交回复
热议问题