我创建了一个应用程序,它使用带有寻呼机适配器的viewr寻址器的imageslider。我使用不同的图像和不同的图像数量创建了大约5个使用imageslider的活动。但是当在手机上运行应用程序时,它显示相同的图像集和相同的计数。请查看3个使用imageslider的活动。我无法弄清楚问题。 第一项活动
public class customSwipe3 extends PagerAdapter {
private int[] imageResources = {R.drawable.vcard_a,R.drawable.vcard_b,R.drawable.vcard_c,R.drawable.vcard_d,R.drawable.vcard_e};
private Context ctxb;
private LayoutInflater layoutInflaterb;
public customSwipe3(Context e) {
ctxb=e;
}
@Override
public int getCount() {
return imageResources.length;
}
@Override
public Object instantiateItem(ViewGroup containerb,int positionb){
layoutInflaterb = (LayoutInflater) ctxb.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView3 =layoutInflaterb.inflate(R.layout.activity_custom_swipe3,containerb,false);
ImageView imageView3 = (ImageView)itemView3.findViewById(R.id.swip_image_view3);
TextView textView3 =(TextView)itemView3.findViewById(R.id.imagecount3);
imageView3.setImageResource(imageResources[positionb]);
textView3.setText("Design No :"+positionb);
containerb.addView(itemView3);
return itemView3;
}
@Override
public void destroyItem(ViewGroup containerb ,int positionb ,Object objectb){
containerb.removeView((LinearLayout) objectb);
}
@Override
public boolean isViewFromObject(View viewb,Object objectb) {
return (viewb==objectb);
}
代码2
public class customSwipe1 extends PagerAdapter {
private int[] imageResourcea = {R.drawable.brochure_a,R.drawable.brochure_b,R.drawable.brochure_c,R.drawable.brochure_d,R.drawable.brochure_e,R.drawable.brochure_f};
private Context ctxa;
private LayoutInflater layoutInflatera;
public customSwipe1(Context d) {
ctxa=d;
}
@Override
public int getCount() {
return imageResourcea.length;
}
@Override
public Object instantiateItem(ViewGroup containera,int positiona){
layoutInflatera = (LayoutInflater) ctxa.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemViewa =layoutInflatera.inflate(R.layout.activity_custom_swipe1,containera,false);
ImageView imageViewa = (ImageView)itemViewa.findViewById(R.id.swip_image_view1);
TextView textViewa =(TextView)itemViewa.findViewById(R.id.imagecount1);
imageViewa.setImageResource(imageResourcea[positiona]);
textViewa.setText("Brochure No :"+positiona);
containera.addView(itemViewa);
return itemViewa;
}
@Override
public void destroyItem(ViewGroup containera ,int positiona ,Object objecta){
containera.removeView((LinearLayout) objecta);
}
@Override
public boolean isViewFromObject(View viewa,Object objecta) {
return (viewa==objecta);
}
代码3
public class customSwipe4 extends PagerAdapter {
private int[] imageResources = {R.drawable.letterheads_a,R.drawable.letterhead_b};
private Context ctxc;
private LayoutInflater layoutInflaterc;
public customSwipe4(Context f) {
ctxc =f;
}
@Override
public int getCount() {
return imageResources.length;
}
@Override
public Object instantiateItem(ViewGroup containerlh, int positionlh) {
layoutInflaterc = (LayoutInflater) ctxc.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView4 = layoutInflaterc.inflate(R.layout.activity_custom_swipe4, containerlh, false);
ImageView imageView4 = (ImageView) itemView4.findViewById(R.id.swip_image_view4);
TextView textView4 = (TextView) itemView4.findViewById(R.id.imagecount4);
imageView4.setImageResource(imageResources[positionlh]);
textView4.setText("Design No :" + positionlh);
containerlh.addView(itemView4);
return itemView4;
}
@Override
public void destroyItem(ViewGroup containerlh, int positionlh, Object objectlh) {
containerlh.removeView((LinearLayout) objectlh);
}
@Override
public boolean isViewFromObject(View viewlh, Object objectlh) {
return (viewlh == objectlh);
}
答案 0 :(得分:0)
在设置适配器的地方添加代码,适配器看起来很好