我有一个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
}
});
}
}
}
截图:
其他信息:
答案 0 :(得分:0)
尝试学习this answer然后更改代码,以便在调用'notifyDataSetChanged()'之前更新'updateBananas'listArray的示例。对notify的调用是更新您正在使用的适配器中的View的信号。
在您的代码中,getYouTube ...需要更新适配器具有引用的数组对象。
您应该能够通过从代码中的示例实现相同的连接来获得它。