I am having a gridView with each item having an image to be loaded. I have used adapter to render the image. I am assigning images as gridView items using resource ID array created using images in drawable folder.
The problem is gridView is being displayed with only 12 images(which fits the view without scrolling). I have around 40 images resource ID in that array. the getView is called only 12-13 times.
Could you pleae help me how to display all 40 images on grid view? Do i need to explicitly add scrollpane in grid.xml?
Below is the grid.xml layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/wooden_background"
android:id="@+id/RootView">
<GridView
android:id="@+id/gridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:stretchMode="columnWidth"
android:padding="5dp"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:gravity="center"
android:maxWidth="150dip"
android:maxHeight="150dip" >
</GridView>
</LinearLayout>
Below is the getView function inside adapter
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi;
if (convertView == null){ // if it's not recycled, initialize some attributes
vi = inflater.inflate(R.layout.each_image,parent, false);
}
else{
vi=convertView;
}
/*imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(170,170));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);*/
System.out.println("Inside getView");
ImageView image = (ImageView)vi.findViewById(R.id.imageView);
image.setMaxHeight(150);
image.setMinimumHeight(150);
image.setScaleType(ImageView.ScaleType.FIT_XY );
image.setImageResource(imageIngredientsID[position]);
return vi;
}
How many items the gridview gets depends entirely on your getCount() method in your adapter, what does it return? 12?