ViewGroup读取所有textview

时间:2017-07-08 15:05:35

标签: android viewgroup

如果我使用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();
                            }

1 个答案:

答案 0 :(得分:0)

是试试这个:

 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. 
     }
 }

希望这有帮助。