Background
In android layout file there or lot of UI elements and view group. Sometimes we do not need to give id
value ( unique identifier ) to views. In such scenarios we can't find the view by saying findViewByid()
. hence we cannot manipulate them.
Question is
How we can generate a path for all view of any activity, Example is below:
content>LinearLayout-0>RelativeLayout-3>LinearLayout-0>TextView-2
The meaning of above line is
- Content is main layout
- LinearLayoutis top most layout
- RelativeLayout-3 is 3rd child of top most layout
- LinearLayout is child of 3rd RelativeLayout
- TexView-2 is child of LinearLayout which is 3rd RelativeLayout child of topmost LinearLayout.
So basically I'm looking for function like below:
String path = getViewPath(view);
and
View view = findViewByPath(path)
Use case:
Actually server will broadcast some command to mobile app by menting path of view ,
then mobile app will find the view from the path and change the property of the views