I am showing a Grid view in Alert dialog. Grid view consists of images which are stored in an array.
I am showing 9 images at a time in grid view, now there are two buttons below grid view "Next" & "Previous".
If click on "Next" it will show next 9 images from the array and similarly with "Previous". Please tell me how to proceed and if possible provide me some sample code.
I tried this code, please say if i can use any other logic..
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView;
imageView = new ImageView(mContext);
if(no_of_image < mThumbIds.length && no_of_image < screen_no)
{
if (convertView == null) // if it's not recycled, initialize some attributes
{
imageView.setLayoutPar开发者_如何学JAVAams(new GridView.LayoutParams(80, 80));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setPadding(8, 8, 8, 8);
}
else
{
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[no_of_image]);
no_of_image++;
}
return imageView;
screen_no is the no. of images to be shown in one grid view. in my case it is 9. and mThumbIds is the array from where i am loading the images.
You have to write your own custom adapter for gridview by extending any existing adapter classes. Now when you click on Next the you will just change the dataset of the adapter and call notifydatasetchaged() method on adapter this will refresh gridview automatically. But keep mind that you should change the dataset if and only if you are having next images to be shown. This is just the overlall logic I am sharing with you.
精彩评论