I am using a custom adapter for my grid view which just return an image view of width 1/3 the size of its parent the app is rendering all the view except at position 0 I think its because parent width and height is 0 while rendering first view how can I get parentwidth for the first view i.e view at position 0
here is my getView() method:
public View getView(int position, View convertView, ViewGroup parent) {
super.getView(position, convertView, parent);
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(getContext());
imageView.setLayoutParams(new GridView.LayoutParams((int) (parent
.getMeasuredWidth() / 3f),
(int) (parent.getMeasuredWidth() / 3f)));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
System.out.println(ids[position].intValue());
int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
imageView.setBackgroundDrawable(getContext().getResources()
.getDrawable(R.drawable.shadow_white));
} else {
imageView.setBackground(getContext().getResources().getDrawable(
R.drawable.shadow_white));
}
imageView.setImageResource(ids[position].intValue());
System.out.println("getView" + imageView);
return imageView;
}
and this is my grid view declaration in xml
<GridView
android:id="@+id/category_grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5dp"
android:background="@color/white"
android:numColumns="3"
android:stretchMode="columnWidth" >
</GridView>