Reputation: 8800
In my application, I have inflated a view multiple times dynamically as the data comes from the server. For Example, I am inflating a linearLayout
multiple times. Now I am trying to test the click on these dynamic views with robotium. The problem is that the layouts that are added dynamically have same id and these are added multiple times. How can I click each of the dynamically inflated linearlayouts.
Upvotes: 0
Views: 1991
Reputation: 5819
Here is a static function that does what you want (i think, i do not have the android sdk or anything on my current machine so cannot test). I would not use it as a static function myself, I would put it somewhere that makes sense, but you can do with it what you want!
public static List<View> getViewsById(Solo solo, int id) {
List<View> allViews = getViews();
List<View> matchedViews = new ArrayList<View>();
for(View view : allViews){
if(view!=null && view.getId() == id){
matchedViews.add(view);
}
}
return matchedViews;
}
Upvotes: 1
Reputation: 16120
It can be done by several ways. One simple solution is when you inflate a view, apply a click listener at that time. Like if you are using some loop, in each iteration, add click listener there in loop.
Upvotes: 0
Reputation: 14622
Use solo.getView(view.class,index).performClick();
to get the view in the specific index and click on it.
Upvotes: 0