not getting all images from gridview on item click listener
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(开发者_StackOverflow中文版"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.
精彩评论