Skip to content Skip to sidebar Skip to footer

Dynamic Element Id To SetId(int) - Android

I saw the syntax definition of setId(int) and findViewByID(int). But how we use findViewById(R.id.row1) I tried using this: Object1.setId(Integer.parseInt('repeat')); It showed no

Solution 1:

It's not recommended to set your object id yourself , findViewById make access to your R class that contains pointers to your XML items id.

when you define an id in your Xml Layout file like

android:id="@+id/txtyourId"

in compile time compiler create a reference to your XML Item layout in R class that you can access it from your java code by findViewById

View YourItem = (View)this.findViewById(R.id.txtyourId);

Solution 2:


Solution 3:

You can define your Ids as resources and then use setId() of the view to set it.


Post a Comment for "Dynamic Element Id To SetId(int) - Android"