问题描述
I M在开发从Inter网的GridView显示图片...现在我想通过对GridView的单击事件的所有图像库的应用程序。
我想,我的画廊不应该下载所有图像时,画廊活动called..so,我想从网格视图所有的图像传递到画廊的活动...
有没有什么解决办法传递o下一个活动的GridView的所有图像,。?
我的GridView的图像来自互联网和我不是存储所有图像局部...只是在网格视图中显示。
这是我的code ..
mainfile.java
公共类PhotoList扩展活动
{
捆束;
字符串键;
INT totalPhoto;
ImageView的imageArray [];
HashMap的<弦乐,ArrayList的< ChildPhotos>> childPhotosWithId;
ArrayList的< ChildPhotos> childPhotoList;
串allURL [];
串标题,详细描述;
TextView的PhotosTitle,PhotosDiscription;
公共静态位图[] downloadedChildPhotos;
公共静态INT downloadedChildPhotosIndex = 0;
ImageView的IMG [];
公共无效的onCreate(捆绑savedInstanceState)
{
super.onCreate(savedInstanceState);
的setContentView(R.layout.photo_list);
GridView控件的GridView =(GridView控件)findViewById(R.id.gridview);
捆绑= getIntent()getExtras()。
键= bundle.getString(钥匙);
totalPhoto =的Integer.parseInt(键);
IMG =新ImageView的[totalPhoto]
标题= bundle.getString(标题);
详细描述= bundle.getString(详细描述); childPhotosWithId = PhotosXMLHanler.getChildPhotoWithId();
childPhotoList = childPhotosWithId.get(键);
ChildPhotos C [] =新ChildPhotos [childPhotoList.size()];
allURL =新的String [childPhotoList.size()]; downloadedChildPhotos =新的位图[childPhotoList.size()]; PhotosTitle =(的TextView)findViewById(R.id.photosTitleInGridView);
PhotosDiscription =(的TextView)findViewById(R.id.photoDiscriptionInGridView); PhotosTitle.setText(职称);
PhotosDiscription.setText(详细描述); 的for(int i = 0; I< childPhotoList.size();我++)
{
C [i] =新ChildPhotos();
C [i]于= childPhotoList.get(ⅰ);
字符串URL = C [I] .getChildPhoto();
allURL [I] = URL;
的System.out.println(URL+(I + 1)+ C [I] .getChildPhoto());
} gridview.setAdapter(新ImageAdapter(这一点,allURL)); gridview.setOnItemClickListener(新OnItemClickListener()
{
公共无效onItemClick(适配器视图<>母公司,视图V,INT位置,长的ID)
{
Toast.makeText(PhotoList.this,+编号,Toast.LENGTH_SHORT).show();
GridView控件G =(GridView控件)v.findViewById(R.id.gridview); 的for(int i = 0; I< totalPhoto;我++)
{
IMG [我] =新ImageView的(PhotoList.this); 的System.out.println(形象==>中+ IMG [I] .getId());
} / * 在这里我要来从网格视图所有图片...
* /
//意向意图=新意图(PhotoList.this,GalleryView.class);
//
// startActivityForResult(意向,0); }
});
} 类ImageAdapter扩展了BaseAdapter
{
私人语境mContext;
的String [] allURL;
ImageLoader的ImageLoader的; 公共ImageAdapter(上下文C,的String [] allURL)
{
mContext = C;
this.allURL = allURL;
ImageLoader的=新ImageLoader的(mContext);
} 公众诠释getCount将()
{
返回allURL.length;
} 公共对象的getItem(INT位置)
{
返回null;
}
众长getItemId(INT位置)
{
返回0;
} //创建由适配器引用的每个项目的新的ImageView
公共查看getView(INT位置,查看convertView,父母的ViewGroup){
ImageView的ImageView的;
如果(convertView == NULL)
{
//如果它不回收,初始化一些属性
ImageView的=新ImageView的(mContext);
imageView.setLayoutParams(新GridView.LayoutParams(85,85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8,8,8,8);
}
其他
{
ImageView的=(ImageView的)convertView;
}
imageView.setTag(allURL [位置]); imageLoader.DisplayImage(allURL [位置],PhotoList.this,ImageView的);
///这里我使用的线程里面设置图像backgrund ...如图像来自互联网.. 返回ImageView的;
} }}
,当你在GridView中点击一个图像上可以将该图像存储在一个位图。编写以下code在你的注释部分。
ImageView的IM =(ImageView的)视图。
可绘制D = im.getDrawable();
位图位图=((BitmapDrawable)D).getBitmap();
同样,你也可以将所有的位图作为当图像clicked.Hope这一点,你所寻找的。什么
i m developing an application in which gridview display images from inter net...now i want to pass all image to gallery on gridview's click event..
I want that my gallery should not download all images when gallery activity is called..so,i want to pass all image from grid view to gallery activity...
is there any solution to pass all images of gridview o next activity,.?
My gridview's images are come from internet and i m not storing all images locally...just displaying in grid view.
here is my code..
mainfile.java
public class PhotoList extends Activity
{
Bundle bundle;
String key;
int totalPhoto;
ImageView imageArray[];
HashMap<String,ArrayList<ChildPhotos>> childPhotosWithId;
ArrayList<ChildPhotos> childPhotoList;
String allURL[];
String title,discription;
TextView PhotosTitle,PhotosDiscription;
public static Bitmap[] downloadedChildPhotos;
public static int downloadedChildPhotosIndex=0;
ImageView img[];
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.photo_list);
GridView gridview = (GridView) findViewById(R.id.gridview);
bundle=getIntent().getExtras();
key=bundle.getString("key");
totalPhoto=Integer.parseInt(key);
img=new ImageView[totalPhoto];
title=bundle.getString("title");
discription=bundle.getString("discription");
childPhotosWithId=PhotosXMLHanler.getChildPhotoWithId();
childPhotoList=childPhotosWithId.get(key);
ChildPhotos c[]=new ChildPhotos[childPhotoList.size()];
allURL=new String[childPhotoList.size()];
downloadedChildPhotos=new Bitmap[childPhotoList.size()];
PhotosTitle=(TextView)findViewById(R.id.photosTitleInGridView);
PhotosDiscription=(TextView)findViewById(R.id.photoDiscriptionInGridView);
PhotosTitle.setText(title);
PhotosDiscription.setText(discription);
for(int i=0;i<childPhotoList.size();i++)
{
c[i]=new ChildPhotos();
c[i]=childPhotoList.get(i);
String url=c[i].getChildPhoto();
allURL[i]=url;
System.out.println("url "+(i+1)+c[i].getChildPhoto());
}
gridview.setAdapter(new ImageAdapter(this,allURL));
gridview.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
Toast.makeText(PhotoList.this, "" +id, Toast.LENGTH_SHORT).show();
GridView g=(GridView)v.findViewById(R.id.gridview);
for(int i=0;i<totalPhoto;i++)
{
img[i]=new ImageView(PhotoList.this);
System.out.println("image ==>"+img[i].getId());
}
/*
here i want to fetch all images from grid view...
*/
// Intent intent=new Intent(PhotoList.this,GalleryView.class);
//
// startActivityForResult(intent, 0);
}
});
}
class ImageAdapter extends BaseAdapter
{
private Context mContext;
String[] allURL;
ImageLoader imageLoader;
public ImageAdapter(Context c,String[] allURL)
{
mContext = c;
this.allURL=allURL;
imageLoader = new ImageLoader(mContext);
}
public int getCount()
{
return allURL.length;
}
public Object getItem(int position)
{
return null;
}
public long getItemId(int position)
{
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null)
{
// if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
}
else
{
imageView = (ImageView) convertView;
}
imageView.setTag(allURL[position]);
imageLoader.DisplayImage(allURL[position],PhotoList.this,imageView);
///here i use thread which set image in backgrund...as images come from internet..
return imageView;
}
}
}
As and when you click on one image in gridview you can store that image in a bitmap. Write the following code in your commented portion.
ImageView im=(ImageView) view;
Drawable d = im.getDrawable();
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
Likewise you can store all the bitmap as when the image is clicked.Hope this what you are looking for.
这篇关于没有项目的点击监听器正从gridview的所有图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!