在我的活动中,我得到了应该在幻灯片中显示的图像列表,
现在应该显示的图像列表的来源来自 JSON,所以我解析了 json 并从 Appfolder/app_content 中获取了我需要显示的图像列表
我有课:
主要活动:
public class MainActivity extends Activity {
ArrayList<String> imageSlideList = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Get Intent- Extra
Intent intent = getIntent();
String swpImgSImgs = intent.getStringExtra("swpImgS");
try {
JSONArray array = new JSONArray(swpImgSImgs);
for (int i = 0 ; i< array.length(); i++){
String imageList = array.getString(i);
FileOperation fo= new FileOperation();
File dir=fo.createFileManagerInsidePackage(AppContext.getAppContext());
String imagePath = dir+"/"+imageList;
imageSlideList.add(imagePath);
}
} catch (JSONException e) {
e.printStackTrace();
}
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
ImageAdapter adapter = new ImageAdapter(this);
viewPager.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return false;
}
}
适配器:
public class SwipingImageSlidesAdapter extends PagerAdapter {
Context context;
//I need to use files that are in json
private int[] GalImages = new int[] {
R.drawable.camera,
R.drawable.camera
};
SwipingImageSlidesAdapter(Context context){
this.context=context;
}
@Override
public int getCount() {
return GalImages.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setImageResource(GalImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
现在我必须做哪些更改才能显示来自应用程序文件夹(App/app_content)的图像,而不是使用我imageSlideList
在 MainActivity 中创建的 ArrayList 使用 R.id.imageName?