Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android. Find view by tag

I have a dynamically created View and want to find it by tag, is this possible? I know the function findViewById, is there something similar for tags?

like image 961
BenG Avatar asked Jun 09 '14 08:06

BenG


1 Answers

LinearLayout linLayout = (LinearLayout)findViewWithTag("layout1");

but I don't think you need tag for dynamic view. You can retrieve dynamic resource by following code

for (int i=0; i < total_resource; i++) {
  //retrieve id dynamically
  int id = getResources().getIdentifier("resource"+i, "id", getPackageName());
  TextView myText = (TextView) findViewById(id); // get the element
}
like image 23
user3384985 Avatar answered Oct 17 '22 01:10

user3384985