The Key Must Be an Application-Specific Resource Id

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



Leave a reply



Submit