private Integer images[] = {R.drawable.mba,R.drawable.lifestylemin,R.drawable.jee,R.drawable.comic,R.drawable.defence};// private ReaderVIEw mReader;// ImageVIEw imagegallery;linearLayout im1;linearLayout imagegallery;linearLayout imagegallery2;ImageVIEw imageVIEw;public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) { VIEw vIEw=inflater.inflate(R.layout.tab2,container,false); // init Plugpdf linearLayout adcat=(linearLayout)vIEw.findVIEwByID(R.ID.adcat); adcat.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { startActivity(new Intent(getActivity(),ebookSelection.class)); } }); imagegallery = (linearLayout) vIEw.findVIEwByID(R.ID.imagegallery); imagegallery2 = (linearLayout) vIEw.findVIEwByID(R.ID.imagegallery2); addImagesToThegallery(); //edit code for(int i=0;i<images.length;i++){ final ImageVIEw imageVIEw = (ImageVIEw) getimageVIEw(images[i]); imageVIEw.setonClickListener(new VIEw.OnClickListener() { public voID onClick(VIEw v) { Intent i=new Intent(getActivity(),book.class); int ID=imageVIEw.getID(); i.putExtra("ID",ID); startActivity(i); } }); } //// return vIEw;}private voID addImagesToThegallery() { for (Integer image : images) { imagegallery.addVIEw(getimageVIEw(image)); imagegallery2.addVIEw(getimageVIEw(image)); }}private VIEw getimageVIEw(Integer image) { ImageVIEw imageVIEw = new ImageVIEw(getActivity().getApplicationContext()); linearLayout.LayoutParams lp = new linearLayout.LayoutParams(260,400); lp.setmargins(0,10,0); imageVIEw.setLayoutParams(lp); imageVIEw.setimageResource(image); imageVIEw.setScaleType(ImageVIEw.ScaleType.FIT_XY); return imageVIEw;}
我想为每个图像制作单独的点击监听器,以便我可以从不同的图像执行不同的尝试.
Thanxx提前.
编辑:使用ImageResource在imageVIEw上添加TAG,然后在图像OnClick方法上恢复TAG,如下所示:
private VIEw getimageVIEw(Integer image,Integer index) { ImageVIEw imageVIEw = new ImageVIEw(this.getApplicationContext()); linearLayout.LayoutParams lp = new linearLayout.LayoutParams(260,0); imageVIEw.setLayoutParams(lp); imageVIEw.setimageResource(image); //Create a TAG on your Strings Resources //"IMAGE_TAG" with any value imageVIEw.setTag(R.string.IMAGE_TAG,image); imageVIEw.setScaleType(ImageVIEw.ScaleType.FIT_XY); imageVIEw.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { int image = (int)v.getTag(R.string.IMAGE_TAG); switch (image) { case R.drawable.mba: { //action for your image } break; //and so on.. } } }); return imageVIEw;}总结
以上是内存溢出为你收集整理的android – 如何在水平ScrollView中为图像制作单击侦听器全部内容,希望文章能够帮你解决android – 如何在水平ScrollView中为图像制作单击侦听器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)