【问题标题】:how to get tag of dynamically created linear layout and it's child ImageView如何获取动态创建的线性布局的标签及其子 ImageView
【发布时间】:2023-03-07 20:59:02
【问题描述】:

Parent_LinearLayout

        LinearLayout
             TextView
             LinearLayout

我在 XML 中有一个父线性布局。 我动态创建了一个线性布局,其子元素是 TextView 和 A 线性布局。 我将此布局添加到父线性布局中。

现在我的问题是如何获取线性布局的标签(第 4 个)及其子标签(稍后我将动态添加)。

for(int i=0;i<parent_Layout.getChildCount();i++){
                    View v=parent_Layout.getChildAt(i);
                    Toast.makeText(getApplicationContext(),""+parent_Layout.getChildCount() , Toast.LENGTH_LONG).show();

                }

我正在尝试做这样的事情,但我不知道如何实现这一目标

【问题讨论】:

    标签: android android-layout layout dynamic


    【解决方案1】:

    您可以在布局上使用 setTag() 之类的东西...然后使用 getTag() 检索布局。希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2023-03-31
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多