Search code examples
androidviewgroup

ViewGroup read all textview


If I use ViewGroup, Is have any method can read all 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();
                            }

Solution

  • Yes Try this :

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

    Hope this helps.