3

I have ViewPager with N tabs with StickyListHeadersListView inside each of them. I'd like to perform click on one of the list item. How could I do that? thanks!

PS: I'm interested in Espresso test code only

Kid24
  • 4,401
  • 4
  • 23
  • 19
  • are you writing your own adapter? – Shahzeb May 20 '15 at 05:02
  • What kind of elements / objects do your lists have? Check this question http://stackoverflow.com/questions/22965839/espresso-click-by-text-in-list-view which should give you an idea about clicking on list items. Also, swiping across tabs in the viewpager is pretty straightforward, there's a viewaction defined for that. You need to provide more information (some code that you've tried) if you really need help. Why would I spend my time guessing what you're actually trying to achieve when your research/trial&error efforts are minimal? – appoll May 20 '15 at 08:20

3 Answers3

3

I've found the solution myself. The main issue - StickyListHeadersListView is a wrapper around ListView, it doesn't extend ListView. So we can't work with adapter directly, but we can do this:

onData(anything()).inAdapterView(allOf(
  isAssignableFrom(AdapterView.class), 
  isDescendantOfA(withId(R.id.list)), 
  isDisplayed()))
.atPosition(1).perform(click());
Kid24
  • 4,401
  • 4
  • 23
  • 19
-2

Put this code in method where you are adding your view in 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();
}
NehaK
  • 2,639
  • 1
  • 15
  • 31
-3

With Listview, you put into fragment.view pager have fragment. after you can check click listitem in fragment. Custom :https://github.com/JakeWharton/ViewPagerIndicator

QuestionAndroid
  • 881
  • 1
  • 8
  • 25