Reputation: 15
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 possible? if so how do I go about doing this?
I'll put the code:
private void sxhmatismos7(String[][] pinakas)
{
TextView n;
int i=0;
for (i=0;i<12;i++)
{
n = (TextView) findViewById(R.id."HERE VALUE OF i");
if (n.getText().equals(pinakas[0][0]))
{
n.setVisibility(View.VISIBLE);
}
}
}
Upvotes: 0
Views: 3600
Reputation: 8866
Something like this should work:
int id = resources.getIdentifier(String.valueOf(i), "id", "com.my.package");
n = (TextView) findViewById(id);
Upvotes: 3
Reputation: 6104
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.
Upvotes: 1
Reputation: 485
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);
.
Upvotes: 0