Espresso: how to click a StickyListHeadersListView item inside a viewpager

I have an N tabbed ViewPager with StickyListHeadersListView inside each one. I want to click on one of the list items. How could I do this? thank!

PS: I'm only interested in the Espresso test code

+3


source to share


3 answers


I found a solution myself. The main problem is StickyListHeadersListView is a wrapper around the ListView, it doesn't extend the ListView. Therefore, we cannot work with the adapter directly, but we can do it:



onData(anything()).inAdapterView(allOf(
  isAssignableFrom(AdapterView.class), 
  isDescendantOfA(withId(R.id.list)), 
  isDisplayed()))
.atPosition(1).perform(click());

      

+3


source


Place this code in the method where you add your view to the viewPager: -



for(int i=0;i<arrPagerItems.size();i++)
{
    View viewPager;
    ListView listView;

    viewPager = inflater.inflate(R.layout.layout_pager,null);

    listView = (ListView) viewPager.findViewById(R.id.listView);

    listChat.setOnItemClickListener(new OnItemClickListener(){
    @Override
    public void onItemClick(AdapterView<?> arg0, View listView,int position,long arg3) {

            //do your task

            }
    });

    viewPagerAdapter.addView(viewPager, i);
    viewPagerAdapter.notifyDataSetChanged();
}

      

-2


source


With Listview, you put in the fragment player .view there is a fragment. after you can check the click list in the snippet. Custom: https://github.com/JakeWharton/ViewPagerIndicator

-3


source







All Articles