0

我有一个 youtube 播放列表:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        final ActionBar actionBar = getActionBar();
        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();

    }

...

我有一个 ViewPager/PagerAdapter:

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

        public ImagePagerAdapter() {
            super();
            // setOnPageChangeListener(mPageChangeListener);
        }

        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);
        }

        private final ViewPager.SimpleOnPageChangeListener mPageChangeListener = new ViewPager.SimpleOnPageChangeListener() {

            @Override
            public void onPageSelected(final int position) {
                onTabChanged(mPager.getAdapter(), mCurrentTabPosition, position);
                mCurrentTabPosition = position;

            }
        };

        public View getView(int position, View convertView, ViewGroup parent) {
            View vi=convertView;
            if (convertView == null) {
                convertView = LayoutInflater.from(context)
                  .inflate(R.layout.home, parent, false);
            }

            ImageView imageView = new ImageView(context);
            ImageView imageView = (ImageView)vi.findViewById(R.drawable.selstation_up_btn);
            imageView.setImageResource(imageView.getImage());

            return convertView;
        }

        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

                View vg = findViewById(R.layout.home);
                vg.invalidate();
            }
            final ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);

            viewPager.setOnPageChangeListener(new OnPageChangeListener() {

                int oldPos = viewPager.getCurrentItem();

                @Override
                public void onPageScrolled(int position, float arg1, int arg2) {

                    if (position > oldPos) {
                        // Moving to the right

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

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

                @Override
                public void onPageScrollStateChanged(int arg0) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onPageSelected(int arg0) {
                    // TODO Auto-generated method stub

                }

            });

        }
    }
    }

截屏:

在此处输入图像描述

问题:

我如何连接这两者 - 所以当我刷 ViewPager/PagerAdapter: 它改变了值: String PLAYLIST

我需要根据 ViewPager/PagerAdapter 选择更改它的值。

例子:

if R.drawable.classical_up_btn {

String PLAYLIST = "TheMozARTGROUP‎";

}

或者

 if R.drawable.country_up_btn {

   String PLAYLIST = "TimMcGrawVEVO‎";
}
4

1 回答 1

0

如果我正确理解您的问题,您可以在 onPageChangeListener 中更改类级别变量播放列表。 int positiononPageScrolled 中的第一个显示项目的索引。

附带说明一下,所有大写字母都应保留给常量。任何可以在代码中更改的变量都应以小写字母开头。

于 2013-12-11T19:15:22.273 回答