How to setCurrentPage in ViewPager according to user selection & how do I know which list item called the activity

前端 未结 1 1636
日久生厌
日久生厌 2021-01-18 21:39

I\'m new to Android programming.

I have a list of items, when the user clicks on an item it takes them to a screen with that item details.

I wa

相关标签:
1条回答
  • 2021-01-18 21:40

    In the onItemClickListener() you need to add an extra to the intent so you can get it when that activity launches.

    n.putExtra("POSITION_KEY", position);
    

    In the ViewPagerClass onCreate() using the

    int position = getIntent().getIntExtra("POSITION_KEY", 0);
    mPager.setCurrentItem(position);
    

    That should do what you are wanting to do.

    0 讨论(0)
提交回复
热议问题