0

我正在尝试在我的源代码中实现 viewPager,并在该行设置了一个断点:

if (position > oldPos) {

但是由于某种原因,在左右滑动 viewPager 时,我似乎从未到达调试器中的断点。我已经查看了很多次我的来源,但我似乎无法准确指出是什么原因造成的。

非常感谢任何建议。

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        final ActionBar actionBar = getActionBar();
        final ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);

        viewPager.setAdapter(adapter);

        actionBar.setCustomView(R.layout.actionbar_custom_view_home);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        drawerListViewItems = getResources().getStringArray(R.array.items);
        drawerListView = (ListView) findViewById(R.id.left_drawer);
        drawerListView.setAdapter(new ArrayAdapter<String>(this,
                R.layout.drawer_listview_item, drawerListViewItems));

        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        actionBarDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
        drawerLayout, /* DrawerLayout object */
        R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
        R.string.drawer_open, /* "open drawer" description */
        R.string.drawer_close /* "close drawer" description */
        );
        drawerLayout.setDrawerListener(actionBarDrawerToggle);

        getActionBar().setDisplayHomeAsUpEnabled(true);

        drawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
                GravityCompat.START);

        listView = (VideosListView) findViewById(R.id.videosListView);
        listView.setOnVideoClickListener(this);
        new GetYouTubeUserVideosTask(responseHandler, playlist).execute();
        setOnPageChangeListener(mPageChangeListener);
        final ViewPager.SimpleOnPageChangeListener mPageChangeListener = new ViewPager.SimpleOnPageChangeListener() {

            @Override
            public void onPageSelected(final int position) {
                onTabChanged(mPager.getAdapter(), mCurrentTabPosition, position);
                mCurrentTabPosition = position;
                int oldPos = viewPager.getCurrentItem();
                if (position > oldPos) {
                    // Moving to the right
                    String playlist = "TheMozARTGROUP‎";
                    new GetYouTubeUserVideosTask(responseHandler, playlist)
                            .execute();

                    View vg = findViewById(R.layout.home);
                    vg.invalidate();

                } else if (position < oldPos) {
                    // Moving to the Left

                    String playlist = "TheMozARTGROUP‎";
                    new GetYouTubeUserVideosTask(responseHandler, playlist)
                            .execute();

                    View vg = findViewById(R.layout.home);
                    vg.invalidate();

                }
            }

            private void onTabChanged(PagerAdapter adapter,
                    int mCurrentTabPosition, int position) {
                // TODO Auto-generated method stub

            }
        };

    }

    private void setOnPageChangeListener(
            OnPageChangeListener mPageChangeListener2) {
        // TODO Auto-generated method stub

    }

    Handler responseHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            populateListWithVideos(msg);
        };
    };

    private void populateListWithVideos(Message msg) {
        Library lib = (Library) msg.getData().get(
                GetYouTubeUserVideosTask.LIBRARY);
        listView.setVideos(lib.getVideos());
    }

    @Override
    protected void onStop() {
        responseHandler = null;
        super.onStop();
    }

    @Override
    public void onVideoClicked(Video video) {
        Intent intent = new Intent(this, Player.class);
        intent.putExtra("id", video.getId());
        intent.putExtra("title", video.getTitle());
        intent.putExtra("uploader", video.getUploader());
        intent.putExtra("viewCount", video.getviewCount());
        startActivity(intent);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        actionBarDrawerToggle.onConfigurationChanged(newConfig);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private class ImagePagerAdapter extends PagerAdapter {
        public ImagePagerAdapter(Activity act, int[] mImages,
                String[] stringArra) {
            imageArray = mImages;
            activity = act;
            stringArray = stringArra;
        }

        // this is your constructor
        public ImagePagerAdapter() {
            super();

        }

        private int[] mImages = new int[] { R.drawable.selstation_up_btn,
                R.drawable.classical_up_btn, R.drawable.country_up_btn,
                R.drawable.dance_up_btn, R.drawable.hiphop_up_btn,
                R.drawable.island_up_btn, R.drawable.latin_up_btn,
                R.drawable.pop_up_btn, R.drawable.samba_up_btn };

        private String[] stringArray = new String[] { "vevo",
                "TheMozARTGROUP‎", "TimMcGrawVEVO‎", "TiestoVEVO‎",
                "EminemVEVO‎" };

        @Override
        public int getCount() {
            return mImages.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == ((ImageView) object);
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            Context context = Home.this;
            ImageView imageView = new ImageView(context);
            imageView.setScaleType(ScaleType.FIT_XY);
            imageView.setImageResource(mImages[position]);
            ((ViewPager) container).addView(imageView, 0);
            return imageView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            ((ViewPager) container).removeView((ImageView) object);
        }

        protected void onTabChanged(final PagerAdapter adapter,
                final int oldPosition, final int newPosition) {
            // Calc if swipe was left to right, or right to left
            if (oldPosition > newPosition) {
                // left to right
            } else {
                // right to left


            }
            final ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);

        }
    }
}
4

2 回答 2

0

断点具体在哪里?如果它在方法声明中,它可能不会被触发,具体取决于您的 IDE。尝试将它放在方法本身中,所以在你的情况下:

**breakpoint** if (position > oldPos) {
于 2013-12-11T21:27:08.530 回答
0

您永远不会调用该代码。该行位于 onTabChanged 内部,仅由 mPageChangeListener 调用,从未使用过。所以当然,你永远不会到达那个断点。

于 2013-12-11T21:36:33.650 回答