public class ViewPagerAdapter2 extends PagerAdapter {
Context context;
String[] image1;
String[] description;
LayoutInflater inflater;
public ViewPagerAdapter2(Context context, String[] image1,String[] description) {
this.context = context;
this.image1 = image1;
this.description=description;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((LinearLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
TextView des;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.slider, container,
false);
des = (TextView) itemView.findViewById(R.id.slider_des);
des.setText(description[position]);
AQuery aq = new AQuery(itemView);
aq.id(R.id.imageView1).image(image1[position], true, true, 0, 0, null, AQuery.FADE_IN, AQuery.RATIO_PRESERVE);
((ViewPager) container).removeView(itemView);
((ViewPager) container).addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((LinearLayout) object);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return description.length;
}
}
这正是您想要的实现...现在声明文本视图内容的变量,声明图像视图,将它们绑定在一起...这应该可以工作...在您的活动中,按照声明的顺序将变量传递给适配器. 该解决方案将完美无缺。我使用查询从 url 获取图像。您可以简单地传递图像资源并通过imageview.setImageResource();
方法绑定它