Get ResourceId for a programatically created control in Android -
I have made control of Android by reading XML
For example
checkbox checkbox = new checkbox (this); Checkbox.setText ("text");
I would like to get values dynamically at the later level in the control
view view = this.findViewById (resId); Bool checked = (see (checkbox). the inspection ();
How can I "resId" for the practical control of control? I tried to use checkbox.getId ()
but it is returning to 0
You keep the context of your control better and use it to set the values.
Maps & lt; String, checkbox & gt; Checkbox = new hashmap & lt; String, checkbox & gt; (); ... checkboxes. Input ("checkbox 1", new checkbox (this)); ... checkbox checkbox = checkbox .get ("checkbox 1");
But if you really want an ID, then you can set your custom ID through the setId
method as suggested by Merlewade but with TRIBLES Android has created an ID to avoid. Create an XML resource object:
& lt; Item type = "id" name = "your_super_puper_id" />
and then use it: See to search for
xxx.setId (R.id.your_super_puper_id)
You can use tagging by using the setTag
method, you can add an object to a view and then the object through the findViewWithTag
method You can use it to look at.
string superPuperStringId = "checkBox1"; SomeView.setTag (superPuperStringId); ... see = some electricity group.FindviewWithTags (SuperPopStringIDID);
In addition to this, you can create your checkbox through XML and specify ID there.
Comments
Post a Comment