I saw the syntax definition of setId(int)
and findViewByID(int)
.
But how we use findViewById(R.id.row1)
I tried using
You can define your Ids as resources and then use setId() of the view to set it.
You can use setId(int)
only for objects extending View class.
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);