1

我有查看寻呼机来每天显示数据。我设置了当前项目的位置。这里是编码..

viewPager = (ViewPager) findViewById(R.id.pager);
    pagerAdapter = new DashboardViewAdapter(getSupportFragmentManager(), selectedDate);

    daoManager = OpenHelperManager.getHelper(this, DAOManager.class);

    viewPager.setAdapter(pagerAdapter);

    Date d = pagerAdapter.getDate(365);
    Log.i("pageAdapter", d.toString());

    viewPager.setCurrentItem(365);
    Log.i("viewAdapter", viewPager.getCurrentItem()+"");

    viewPager.setOnPageChangeListener(new OnPageChangeListener(){

        public void onPageScrollStateChanged(int arg) {

        }

        public void onPageScrolled(int arg0, float arg1, int arg2) {
            // TODO Auto-generated method stub

        }

        public void onPageSelected(int position) {
            Date d = pagerAdapter.getDate(viewPager.getCurrentItem());
            monthTitleTextView.setText(formatter.format(d));
            selectedDate = d;
            Log.i("onPageSelected", selectedDate.toString());
            Log.i("onPageSelected", viewPager.getCurrentItem()+"");
        }

    });

而且我有onSaveInstanceState方法来存储selectedDate.

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putSerializable(DAOManager.SELECTED_DATE, selectedDate);
    Log.i("onSaveInstanceState", selectedDate.toString());
}

我运行编码,我得到了这个结果。

08-02 13:03:17.868: I/pageAdapter(16770): Fri Aug 02 00:00:00
 GMT+06:30 2013 08-02 13:03:17.868: I/viewAdapter(16770): 365

我滑了一天。我得到了这个结果。

08-02 13:07:17.278: I/onPageSelected(16770): Sat Aug 03 00:00:00
GMT+06:30 2013 08-02 13:07:17.278: I/onPageSelected(16770): 366

之后我旋转屏幕来改变方向。结果是这样的。

08-02 13:10:27.558: I/onSaveInstanceState(16770): Sat Aug 03 00:00:00 GMT+06:30 2013
08-02 13:10:27.748: I/dateList (16770): 731 from Fri Aug 03 00:00:00 GMT+06:30 2012-- to Sun Aug 03 00:00:00 GMT+06:30 2014
08-02 13:10:27.748: I/pageAdapter(16770): Sat Aug 03 00:00:00 GMT+06:30 2013
08-02 13:10:27.748: I/viewAdapter(16770): 365
08-02 13:10:27.888: I/onPageSelected(16770): Sun Aug 04 00:00:00 GMT+06:30 2013
08-02 13:10:27.888: I/onPageSelected(16770): 366

我的问题是,在屏幕方向改变后,即使我在方法中设置了位置,当前的项目位置也是陈旧的oncreate。我想知道如何刷新视图寻呼机的当前项目位置。

谢谢。

4

1 回答 1

0

试试这个,它可以帮助你

 mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                Toast.makeText(SampleCirclesWithListener.this, "Changed to page " + position, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
于 2013-08-02T07:14:05.670 回答