1
我在可繪製文件夾中有多個圖像,但我只想根據在之前的ListView活動中點擊的項目加載某些圖像。所以我想學習如何延遲加載圖像,而不是硬編碼到我的XML文件。我是一個新手,並試圖教自己的android來自ios開發背景。預先感謝您的幫助。
私有類MyPagerAdapter擴展PagerAdapter {如何更改基於List項目加載到ViewPager中的圖像點擊
public int getCount(){
return 3;
}
public Object instantiateItem(View collection, int position){
LayoutInflater inflater = (LayoutInflater)collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ImageView iv1 = (ImageView) findViewById(R.id.imageView1);
ImageView iv2 = (ImageView) findViewById(R.id.imageView2);
ImageView iv3 = (ImageView) findViewById(R.id.imageView3);
int resId = 0;
switch(position){
case 0:
iv1.setImageResource(R.drawable.amersenna);
resId = R.layout.left;
break;
case 1:
iv2.setImageResource(R.drawable.amersenna);
resId = R.layout.middle;
break;
case 2:
iv3.setImageResource(R.drawable.amersenna);
resId = R.layout.right;
break;
}
View view = inflater.inflate(resId, null);
((ViewPager) collection).addView(view, 0);
return view;
}
@Override
public void destroyItem(View agr0, int agr1, Object agr2) {
((ViewPager) agr0).removeView((View)agr2);
}
@Override
public boolean isViewFromObject(View agr0, Object agr1){
return agr0 == ((View)agr1);
}
@Override
public Parcelable saveState(){
return null;
}
}