LoginSignup
3
3

More than 5 years have passed since last update.

ViewPagerで現在のpageを取得する

Posted at

Google検索などで出てくる推奨されている方法だとArgumentに保存してその値を毎回取り出している。

しかしすべてのPageを一つのFragmentで使い回す&Asynctaskで非同期処理を行っていたら正しいPageのpositionが取得できなかった。

どうすればいいのか分からなかったので取りあえず以下のようにした


----ViewPager class----
public static int pagePosotion;

@Override
    public void onTabSelected(ActionBar.Tab tab,
            FragmentTransaction fragmentTransaction) {
        // When the given tab is selected, switch to the corresponding page in
        // the ViewPager.
        currentPage = tab.getPosition();
        mViewPager.setCurrentItem(tab.getPosition());
    }


----Fragment class----

Log.e("Page position", "" + ViewPagerClassName. pagePosotion)

多分もっと良いやり方とかあると思います。
知っている人がいたら是非教えてください。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3