Rookie
Rookie

Reputation: 8800

click dynamically inflated views using robotium

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

Answers (3)

Paul Harris
Paul Harris

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

Khawar Raza
Khawar Raza

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

Uriel Frankel
Uriel Frankel

Reputation: 14622

Use solo.getView(view.class,index).performClick(); to get the view in the specific index and click on it.

Upvotes: 0

Related Questions