Skip to content Skip to sidebar Skip to footer

Android Findviewbyid() Use Int At Id Field

I have a pretty simple question: int i=0; n = (TextView) findViewById(R.id. 'value of i' ); How can I get this working? I want in the place of id to use my int value, is it possib

Solution 1:

Something like this should work:

intid = resources.getIdentifier(String.valueOf(i), "id", "com.my.package");
n = (TextView) findViewById(id);

Android docs

Solution 2:

There is only one way, you will have to create the TextView Dynamically and add it to your layout, there is a method called:

view.setId(int i);

here you can set the id of your view and can access it.

Solution 3:

You don't use it that way. R.id.value is a Resource Id, typically from your layouts.

R.id.value is a public final int from the R.java file. The Id number is generated by your editor and is something like -11222388. There is almost never a time to not use code that looks like (View) findViewById(R.id.itemId);.

Post a Comment for "Android Findviewbyid() Use Int At Id Field"