在我的活動我理解的應該是在一個幻燈片顯示的圖像列表獲取圖像資源ID圖像,如何從字符串的ArrayList
現在來源爲應顯示圖像的列表來自JSON,所以我已經解析JSON並得到了,我需要從Appfolder/app_content顯示圖像的列表
我有類:
MainActivity:
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;
}
}
阿達PTER:
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);
}
}
現在有什麼變化我一定要使用我在MainActivity創建imageSlideList
是ArrayList中顯示來自應用程序文件夾(應用程序/ app_content),而不是使用R.id.imageName圖像?
謝謝你的幫助:) – star18bit