Android系统.按标签查找视图

Ben*_*enG 15 tags android view find

我有一个动态创建的视图,想要通过标签找到它,这可能吗?我知道这个功能findViewById,标签有类似之处吗?

use*_*985 20

LinearLayout linLayout = (LinearLayout)findViewWithTag("layout1");
Run Code Online (Sandbox Code Playgroud)

但我认为你不需要动态视图的标签.您可以通过以下代码检索动态资源

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
}
Run Code Online (Sandbox Code Playgroud)

  • 您不需要它,但对于要从外部服务更新的动态生成的视图来说它非常方便 (2认同)