I am using Customized grid view. The childs are repeating while loading and changing position while scrolling. Below is the code.
// TODO Auto-generated method stub
// View grid;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// grid = new View(mContext);
if (convertView == null) {
if (gridCount == 0) {
convertView = inflater.inflate(R.layout.customgridxmlfirst,null);
RelativeLayout relativeLayout1 = (RelativeLayout) convertView
.findViewById(R.id.relative_first);
relativeLayout1.getLayoutParams().height = (int) (screenWidth / 2);
relativeLayout1.getLayoutParams().width = (int) (screenWidth / 2.1);
ImageView imageView = (ImageView) convertView
.findViewById(R.id.grid_image_first);
imageView.getLayoutParams().width = (int) (screenWidth / 2.5);
imageView.getLayoutParams().height = (int) (screenWidth / 2.5);
// imageView.setImageBitmap(bitmapBitmaparrayList.get(position));
imageLoader.displayImage(bitmapBitmaparrayList.get(position),
imageView);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ProductDetailFragment gridViewFragment = new ProductDetailFragment();
FragmentManager fm = ((MainActivity) mContext)
.getFragmentManager();
Bundle bundle = new Bundle();
bundle.putInt("positon", position);
String imagurl = bitmapBitmaparrayList.get(position);
bundle.putString("imageurl", imagurl);
gridViewFragment.setArguments(bundle);
fm.beginTransaction()
.replace(R.id.launchfragmentlayout,
gridViewFragment).addToBackStack(null)
.commit();
Toast.makeText(mContext, "Clicked" + position,
Toast.LENGTH_SHORT).show();
}
});
TextView productprice = (TextView) convertView
.findViewById(R.id.productprice);
// productprice.setTextSize(screenWidth/70);
TextView productDetails = (TextView) convertView
.findViewById(R.id.grid_text_desc);
// productDetails.setText(productDescArray.get(position));
// productDetails.setTextSize(screenWidth/70);
TextView productDiscount = (TextView) convertView
.findViewById(R.id.disc_ammount);
productDiscount.setPaintFlags(productDiscount.getPaintFlags()
| Paint.STRIKE_THRU_TEXT_FLAG);
Button shareButton = (Button) convertView
.findViewById(R.id.shareproduct);
shareButton.getLayoutParams().height = (int) (screenWidth / 19);
shareButton.getLayoutParams().width = (int) (screenWidth / 19);
// shareButton.setBackgroundResource(R.drawable.addtocart);
} else if (gridCount == 1) {
convertView = inflater.inflate(R.layout.customgridsecond, null);
RelativeLayout linearLayout = (RelativeLayout) convertView
.findViewById(R.id.relativelaout_sec_image);
linearLayout.getLayoutParams().width = (int) (screenWidth / 2.7);
linearLayout.getLayoutParams().height = (int) (screenWidth / 2.7);
RelativeLayout relativelaout_sec = (RelativeLayout) convertView
.findViewById(R.id.layout_text);
relativelaout_sec.getLayoutParams().height = (int) (screenWidth / 2.9);
TextView productDiscount = (TextView) convertView
.findViewById(R.id.disc_price);
productDiscount.setPaintFlags(productDiscount.getPaintFlags()
| Paint.STRIKE_THRU_TEXT_FLAG);
TextView productDesc = (TextView) convertView
.findViewById(R.id.productdesctxt);
// productDesc.setText(productDescArray.get(position));
ImageView imageView = (ImageView) convertView
.findViewById(R.id.grid_image_sec);
imageView.getLayoutParams().width = (int) (screenWidth / 3);
imageView.getLayoutParams().height = (int) (screenWidth / 3);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ProductDetailFragment gridViewFragment = new ProductDetailFragment();
Bundle bundle = new Bundle();
bundle.putInt("position", position);
bundle.putString("imageurl",
bitmapBitmaparrayList.get(position));
gridViewFragment.setArguments(bundle);
FragmentManager fm = ((MainActivity) mContext)
.getFragmentManager();
fm.beginTransaction()
.replace(R.id.launchfragmentlayout,
gridViewFragment).addToBackStack(null)
.commit();
Toast.makeText(mContext, "Clicked" + position,
Toast.LENGTH_SHORT).show();
}
});
imageLoader.displayImage(bitmapBitmaparrayList.get(position),
imageView);
Button shareButton = (Button) convertView
.findViewById(R.id.sharesecond);
shareButton.getLayoutParams().height = (int) (screenWidth / 19);
shareButton.getLayoutParams().width = (int) (screenWidth / 19);
Button addToCartButton = (Button) convertView
.findViewById(R.id.addto_cart);
addToCartButton.getLayoutParams().width = (int) (screenWidth / 4);
addToCartButton.getLayoutParams().height = (int) (screenWidth / 14);
} else if (gridCount == 2) {
convertView = inflater.inflate(R.layout.customisedgridthird,
null);
RelativeLayout sampleLayout = (RelativeLayout) convertView
.findViewById(R.id.samplelayout);
sampleLayout.getLayoutParams().width = (int) (screenWidth / 1.05);
sampleLayout.getLayoutParams().height = (int) (screenWidth / 1.3);
ImageView imageView = (ImageView) convertView
.findViewById(R.id.grid_image_third);
imageView.getLayoutParams().width = (int) (screenWidth / 2);
imageView.getLayoutParams().height = (int) (screenWidth / 2);
imageLoader.displayImage(bitmapBitmaparrayList.get(position),
imageView);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ProductDetailFragment gridViewFragment = new ProductDetailFragment();
Bundle bundle = new Bundle();
bundle.putInt("position", position);
bundle.putString("imageurl",
bitmapBitmaparrayList.get(position));
gridViewFragment.setArguments(bundle);
gridViewFragment.setArguments(bundle);
FragmentManager fm = ((MainActivity) mContext)
.getFragmentManager();
fm.beginTransaction()
.replace(R.id.launchfragmentlayout,
gridViewFragment).addToBackStack(null)
.commit();
Toast.makeText(mContext, "Clicked" + position,
Toast.LENGTH_SHORT).show();
}
});
Button shareButton = (Button) convertView
.findViewById(R.id.sharethird);
shareButton.getLayoutParams().height = (int) (screenWidth / 19);
shareButton.getLayoutParams().width = (int) (screenWidth / 19);
TextView productDiscount = (TextView) convertView
.findViewById(R.id.disc_price_third);
productDiscount.setPaintFlags(productDiscount.getPaintFlags()
| Paint.STRIKE_THRU_TEXT_FLAG);
TextView producTextView = (TextView) convertView
.findViewById(R.id.productpriceseondgviewthird);
}
}
return convertView;
Depending on the count I am changing Grid Layout its working.
I am using Universal loader to show images using urls
imageLoader.displayImage(bitmapBitmaparrayList.get(position), imageView);
please let me know what wrong I am doing.