The key must be an application-specific resource id
The tag id must be unique so it wants it to be an id created in a resources file to guarantee uniqueness.
If the view will only contain one tag though you can just do
setTag(objContact.onlineid);
Android: View.getTag/setTag and IllegalArgumentException
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)
.
The key must be an application-specific resource id
The tag id must be unique so it wants it to be an id created in a resources file to guarantee uniqueness.
If the view will only contain one tag though you can just do
setTag(objContact.onlineid);
Using Tags to pass data between methods
I suppose you have two options. You could create a POJO that contains all the data you want to pass to your View and then call View#setTag(yourPojo)
.
Alternatively, you could set multiple tags on the View (as you have been trying to do). The problem is that the first argument to View#setTag(int, Object)
is not just a simple int
, it actually must be an ID as specified in the SDK docs:
The specified key should be an id declared in the resources of the
application to ensure it is unique (see the ID resource type).
Fortunately it is fairly easy to define new IDs, the link above describes the process well.
x,y coordinates from xamarin.forms image in android
According to the SetTag documentation you can't set any arbitrary value as the key, but should define an application resource id
The specified key should be an id declared in the resources of the application to ensure it is unique (see the ID resource type). Keys identified as belonging to the Android framework or not associated with any package will cause an IllegalArgumentException to be thrown.
The key is not related to your control, but refers to the tag within the control
Parameters
key: The key identifying the tag
tag: An Object to tag the view with
Hence passing your controls ID does not seem like a very good choice anyway.
Please see the android reference on how to create a resource.
A unique resource ID defined in XML.
[...]res/values/filename.xml
. The filename is arbitrary.
Within this file you can create an ID
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item
type="id"
name="id_name" />
</resources>
The attribute type="id"
is mandatory for ID resources. id_name
can be changed to whatever you like and then referenced in your application
Resource.Id.id_name
(Resource
class should be in the main namespace of your android app).
Related Topics
Android - Firebase Quickstart Email/Password Auth Demo Doesn't Work
When Should One Use Rxjava Observable and When Simple Callback on Android
Android Supporting Multiple Resolution with Multiple Layout Folder
Picasso Loading of Image Spawned Inside Asynctask
Multiple Table SQLite Db Adapter(S) in Android
How to Disable Crashlytics During Development
Problem Loading Swf File in Android
Batch Scripting - If Exist ./Sdcard/File.Any Using Adb
Display Unity Scene as Sub View in Android Studio
How to Calculate Phone's Movement in the Vertical Direction from Rest
How to Import Contacts from Phonebook to Our Application
Out of Memory While Creating Bitmaps on Device
How to Detect When the Notification/System Bar Is Opened
Android Download PDF from Url Then Open It with a PDF Reader
How to Get National Holidays of Selected Country
How to Use an Android Handler to Update a Textview in the UI Thread