我有一个 JSON 请求,它得到了 YouTube 的响应:
@Override
protected Void doInBackground(Void... arg0) {
try {
HttpClient client = new DefaultHttpClient();
HttpUriRequest request = new HttpGet("https://gdata.youtube.com/feeds/api/videos?author="+PLAYLIST+"&v=2&alt=jsonc");
我想使用可滑动的页脚图像(pagerAdapter)来更改字符串 PLAYLIST 的值。我主要关心的是试图弄清楚如何使用如下所示的PagerAdapter来设置以下内容:
String PLAYLIST = "vevo";
String PLAYLIST = "TheMozARTGROUP";
String PLAYLIST = "TimMcGrawVEVO";
String PLAYLIST = "TiestoVEVO";
String PLAYLIST = "EminemVEVO";
然后在PagerAdapter设置 PLAYLIST 的值后立即使用 PLAYLIST 的新值创建一个播放列表:
new GetYouTubeUserVideosTask(responseHandler, PLAYLIST).execute();
我创建了一个包含我想使用的值的新字符串数组。我现在的问题是:如何修改下面的源代码以使用数组值之一设置 PLAYLIST 的值并执行新的播放列表?(目前我的源代码编译但是当我刷PagerAdapter - 没有任何反应)
new GetYouTubeUserVideosTask(responseHandler, PLAYLIST).execute();
当前无法使用的寻呼机适配器:
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();
// 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 };
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.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;
}
};
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
}
});
}
}
}
截屏:
附加信息: