I’m trying to do some touchUtil on a button within a relative layout that does not have an id.
Usually it would look something like:
relativelayout rl1 = (relativelayout) base.findViewById(R.id.layout1);
button btn = (button) rl1.findviewbyId(R.id.buttonX);
touchUtil(btn);
But the one I’m working on is within a ScrollView, RelativeLayout, LinearLayout, (which do not have ids) and then the button.
How can I push that button with touchutils?
You can always use
ViewGroup#getChildAt()to retrieve a View based on an index.Addition
If you have a layout like this:
Then you can traverse the ViewTree like so:
The best scenario is to simply ask the layout designers to add ids to the elements that you want.