【问题标题】:Get children from View [duplicate]从视图中获取孩子[重复]
【发布时间】:2015-03-17 13:39:48
【问题描述】:

我有视图。如何在 View 中获取和编辑子项。

View myTable = inflater.inflate(R.layout.letters_table, container);

// Get and edit myTable children

【问题讨论】:

  • 你的视图真的是一张桌子吗?

标签: android


【解决方案1】:

并非所有Views 都有孩子。只有 ViewGroup 实例有。如果你想得到一个膨胀的View 的孩子试试这个:

if (view instanceof ViewGroup) {
  ViewGroup viewGroup = (ViewGroup) view;
  for(int i = 0; i< viewGroup.getChildCount(); ++i) {
    View child = viewGroup.getChildAt(i);
    // Edit the child
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-13
    • 2012-10-24
    • 1970-01-01
    • 1970-01-01
    • 2018-12-14
    • 2011-01-14
    • 1970-01-01
    • 2020-04-05
    相关资源
    最近更新 更多