【问题标题】:ViewGroup read all textview [closed]ViewGroup 阅读所有文本视图 [关闭]
【发布时间】:2017-07-08 15:05:34
【问题描述】:

如果我使用 ViewGroup,是否有任何方法可以读取所有 TextView?

 ViewGroup viewGroup=(ViewGroup)view.getParent();
  int childCount = viewGroup.getChildCount();
       for (int i = 0; i < childCount; i++) {

                    TextView txtLikeStatus=(TextView)viewGroup.findViewById(R.id.ext);
                    String plus2= txtLikeStatus.getText().toString();
                    Toast.makeText(view.getContext(), "test:"+  txtLikeStatus, Toast.LENGTH_SHORT).show();
                            }

【问题讨论】:

    标签: android viewgroup


    【解决方案1】:

    是的,试试这个:

     ViewGroup vg = (ViewGroup) view.getParent();
     for (int i = 0; i < vg.getChildCount(); i++) {
         View child = vg.getChildAt(i);
         if (child.getClass() == TextView.class) {
         //Do your work here. 
         }
     }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-10
      • 2020-09-27
      • 1970-01-01
      • 2018-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多