I want to get a a childView whose name is “name” inside a ViewGroup. I knew that the nameView is the second item inside the GroupView, so I used following code:
TextView nameView = (TextView)((ViewGroup)view).getChildAt(2); //2 is magic number
However, it is possible that ,in the future, I might add some other Views before the nameView and above code will became invalid. So, I am wondering how could get the ChildView by name, something like:
TextView nameView = (TextView)((ViewGroup)view).getChildByID(R.id.name);
EDIT: thanks to kcoppock. I realize getChildByName("name") does not make sense. So i will purse something like getChildByID.
You method are looking for is View.findViewById(id). Per your example:
(It is not necessary to cast to ViewGroup)
Barry