android


In RecycleView onScrolling images are flickering


This is the code for adapter which I am using. In this I am using Volley for the image loading. My actual problem is that whenever I am trying to scroll all the images the flickering.
So please suggest me the solution to fix the image flickering problem.
public class RecycleViewAdapter extends RecyclerView.Adapter<RecycleViewAdapter.ViewHolder> {
private Activity activity;
private String search;
public List<CategoryItem> catalogsList;
private Context context;
private RequestQueue mRequestQueue;
private SimpleImageLoader newImageLoader;
private int screenWidth, screenHeight;
public ImageContainerResize imageContainerResize;
private Handler mHandler;
private String parentId;
private String title;
private int numFound;
private OnClick onClick;
private String categoriesName;
private boolean isListViewMode;
public ArrayList<String> getCategorySuggestionList() {
return categorySuggestionList;
}
public void setListViewMode(boolean listViewMode) {
isListViewMode = listViewMode;
}
public void setCategorySuggestionList(ArrayList<String> categorySuggestionList) {
this.categorySuggestionList = categorySuggestionList;
}
private ArrayList<String> categorySuggestionList;
private boolean isFashionPart;
public RecycleViewAdapter(Context context, List<CategoryItem> data, String parentID,
String title) {
this.context = context;
this.setSearch("");
mHandler = new Handler();
this.catalogsList = data;
isFashionPart = false;
newImageLoader = Utils.imageLoader;
this.parentId = parentID;
this.title = title;
imageContainerResize = new ImageContainerResize(context);
this.categorySuggestionList = new ArrayList<>();
onClick = (OnClick) context;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View itemView;
if (1 == viewType) {
if (isListViewMode) {
itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.component_list,
viewGroup, false);
} else {
itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_category_c2,
viewGroup, false);
}
} else {
itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.category_suggestions,
viewGroup, false);
}
return new ViewHolder(itemView, viewType, isListViewMode);
}
#Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
if (getItemViewType(position) == 1) {
holder.linearLayout.setVisibility(View.VISIBLE);
CategoryItem categoryItem = this.catalogsList.get(holder.getAdapterPosition());
if (!categoryItem.getCatalogs().isStock()) {
holder.stokHabisTextView.setVisibility(View.VISIBLE);
}
if (categoryItem.getCatalogs().isZeroPercentInstallment()) {
holder.cicilanTextView.setVisibility(View.VISIBLE);
if (!categoryItem.getCatalogs().isStock()) {
holder.dividerGridTextView.setVisibility(View.VISIBLE);
}
}
String product = categoryItem.getCatalogs().getName(), productName, newProductName;
if (product.length() > 35) {
productName = product.substring(0, 20);
newProductName = product.substring(product.length() - 15, product.length());
product = productName + "..." + newProductName;
}
holder.newPriceTextView.setText(categoryItem.getCatalogs().getPriceDisplay());
holder.oldPriceTextView
.setPaintFlags(holder.oldPriceTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
Utils.getDisplaySize(activity);
int widthport = Utils.getWidthDisplayDevice() / 3;
int widthlands = Utils.getHeightDisplayDevice(activity) / 3;
String imageUrl = categoryItem.getCatalogs().getImageUrl();
Log.wtf("imageURL", imageUrl);
if (context.getResources()
.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
imageUrl = imageUrl + Utils.imageCompressionFunction(context, widthport, widthport);
imageContainerResize.setFadeInImageLoader(newImageLoader, imageUrl, holder.imageView,
widthport, widthport);
} else {
imageUrl = imageUrl + Utils.imageCompressionFunction(context, widthlands, widthlands);
imageContainerResize.setFadeInImageLoader(newImageLoader, imageUrl, holder.imageView,
widthlands, widthlands);
}
if (categoryItem.getCatalogs().getStrikeThrughtPriceDisplay() != null) {
holder.oldPriceTextView.setText(categoryItem.getCatalogs().getStrikeThrughtPriceDisplay());
if (categoryItem.getCatalogs().getDiscount() != 0) {
holder.newPriceTextView
.setText(String.format("%s (-%d%%)", categoryItem.getCatalogs().getPriceDisplay(),
categoryItem.getCatalogs().getDiscount()));
} else {
holder.newPriceTextView.setText(categoryItem.getCatalogs().getPriceDisplay());
}
if ("null".equals(categoryItem.getCatalogs().getStrikeThrughtPriceDisplay())) {
holder.oldPriceTextView.setVisibility(View.GONE);
}
}
// sets the title and the subtitle for the current component
final SpannableStringBuilder spannableStringBuilder =
Utils.makeSectionOfTextBold(product, getSearch());
holder.descriptionTextView.setText(spannableStringBuilder);
if (categoryItem.getCatalogs().getPriceDisplay().contains("tidak")) {
holder.newPriceTextView.setText("Not available");
}
if (CategoryC1Activity.FASHION_ENABLE) {
if (isFashionPart) {
setGravityCenter(holder.descriptionTextView, holder.oldPriceTextView,
holder.newPriceTextView);
if (!isListViewMode) {
holder.relative.setGravity(Gravity.CENTER_HORIZONTAL);
holder.linearData.setGravity(Gravity.CENTER_HORIZONTAL);
holder.linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
holder.stokHabisTextView
.setTextColor(ContextCompat.getColor(context, R.color.strike_through_price));
holder.cicilanTextView
.setTextColor(ContextCompat.getColor(context, R.color.strike_through_price));
}
}
}
if (categoryItem.getCatalogs().getProductRating() == 0) {
Utils.hideProductRating(holder.imageViewOne, holder.imageViewTwo, holder.imageViewThree,
holder.imageViewFour, holder.imageViewFive, holder.textViewReviewCount);
} else {
Utils.setRating(categoryItem.getCatalogs(), holder.imageViewOne, holder.imageViewTwo,
holder.imageViewThree, holder.imageViewFour, holder.imageViewFive);
}
holder.textViewReviewCount
.setTextColor(ContextCompat.getColor(context, R.color.textcolor_reviewcount));
holder.textViewReviewCount.setText(String.format(" (%s)",
String.valueOf(categoryItem.getCatalogs().getProductReviewCount())));
holder.parentLinearLayout.setTag(R.id.url_image_cache, imageUrl);
holder.parentLinearLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String id, productName;
id = catalogsList.get(holder.getAdapterPosition()).getCatalogs().getId();
productName = catalogsList.get(holder.getAdapterPosition()).getCatalogs().getName();
// Call Analytics
Utils.blibliProductClicktracking(context, parentId, title, String.valueOf(numFound), id);
BundleProduct bundleProduct = new BundleProduct();
bundleProduct.setId(id);
bundleProduct.setFashion(catalogsList.get(holder.getAdapterPosition()).getCatalogs().isFashion());
bundleProduct.setName(catalogsList.get(holder.getAdapterPosition()).getCatalogs().getName());
bundleProduct
.setPrice(catalogsList.get(holder.getAdapterPosition()).getCatalogs().getStrikeThrughtPriceDisplay());
bundleProduct.setPriceAfterDisc(String.format("%s (-%d%%)",
catalogsList.get(holder.getAdapterPosition()).getCatalogs().getPriceDisplay(),
catalogsList.get(holder.getAdapterPosition()).getCatalogs().getDiscount()));
bundleProduct
.setImageUrl(String.valueOf(holder.parentLinearLayout.getTag(R.id.url_image_cache)));
Utils.intentToProductDetail(activity, bundleProduct);
Utils.measureActions(id, productName, Constants.ACTION_PRODUCT_C2,
Constants.SCREEN_NAME_C2);
}
});
} else if (0 == getItemViewType(position)) {
if (holder.categoriesSuggestionLayout.getChildCount() > 0) {
holder.categoriesSuggestionLayout.removeAllViews();
}
if (0 == position) {
holder.categoriesSuggestionTitle.setVisibility(View.GONE);
holder.closeCategoriesSuggestion.setVisibility(View.GONE);
for (int i = 0; i < categorySuggestionList.size(); i++) {
holder.categoriesSuggestionLayout
.addView(onClick.generateView(categorySuggestionList.get(i)));
}
} else {
if (categorySuggestionList.isEmpty()) {
holder.suggestionRelativeLayout.getLayoutParams().height = 0;
holder.suggestionRelativeLayout.setVisibility(View.GONE);
} else {
holder.suggestionRelativeLayout.setVisibility(View.VISIBLE);
holder.suggestionRelativeLayout.getLayoutParams().height =
RecyclerView.LayoutParams.MATCH_PARENT;
holder.categoriesSuggestionTitle.setVisibility(View.VISIBLE);
holder.closeCategoriesSuggestion.setVisibility(View.VISIBLE);
holder.categoriesSuggestionTitle
.setText(activity.getResources().getString(R.string.suggestion_category_2));
for (String categoriesNameOne : categorySuggestionList) {
final String categoriesName = categoriesNameOne;
TextView categoriesTextView = new TextView(activity);
categoriesTextView.setPadding(20, 20, 20, 20);
categoriesTextView.setTypeface(null, Typeface.BOLD);
categoriesTextView.setTextColor(Color.parseColor("#000000"));
if (categoriesName.length() > 15) {
categoriesTextView.setText(String.format("%s...", categoriesName.substring(0, 15)));
} else {
categoriesTextView.setText(categoriesName);
}
holder.categoriesSuggestionLayout.addView(categoriesTextView);
categoriesTextView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onClick.clickListener(categoriesName);
}
});
}
holder.closeCategoriesSuggestion.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
holder.suggestionRelativeLayout.getLayoutParams().height = 0;
holder.suggestionRelativeLayout.setVisibility(View.GONE);
}
});
}
}
}
}
#Override
public int getItemCount() {
return catalogsList.size();
}
#Override
public int getItemViewType(int position) {
if (catalogsList.get(position).isSection()) {
return 0;
} else {
return 1;
}
}
public static class ViewHolder extends RecyclerView.ViewHolder {
TextView descriptionTextView;
TextView oldPriceTextView;
TextView newPriceTextView;
TextView stokHabisTextView;
TextView cicilanTextView;
TextView dividerGridTextView;
ImageView imageView;
LinearLayout linearLayout;
ImageView imageViewOne;
ImageView imageViewTwo;
ImageView imageViewThree;
ImageView imageViewFour;
ImageView imageViewFive;
TextView textViewReviewCount;
LinearLayout relative;
LinearLayout linearData;
LinearLayout parentLinearLayout;
LinearLayout categoriesSuggestionLayout;
TextView categoriesSuggestionTitle;
ImageView closeCategoriesSuggestion;
RelativeLayout suggestionRelativeLayout;
public ViewHolder(View convertView, int viewType, boolean isListViewMode) {
super(convertView);
if (1 == viewType) {
if (isListViewMode) {
descriptionTextView = (TextView) convertView.findViewById(R.id.title);
oldPriceTextView = (TextView) convertView.findViewById(R.id.old_price);
newPriceTextView = (TextView) convertView.findViewById(R.id.price);
stokHabisTextView = (TextView) convertView.findViewById(R.id.tv_out_of_stock);
cicilanTextView = (TextView) convertView.findViewById(R.id.tv_installment);
dividerGridTextView = (TextView) convertView.findViewById(R.id.divider_grid);
imageView = (ImageView) convertView.findViewById(R.id.image);
linearLayout = (LinearLayout) convertView.findViewById(R.id.product_rating);
imageViewOne = (ImageView) convertView.findViewById(R.id.ratingone);
imageViewTwo = (ImageView) convertView.findViewById(R.id.ratingtwo);
imageViewThree = (ImageView) convertView.findViewById(R.id.ratingthree);
imageViewFour = (ImageView) convertView.findViewById(R.id.ratingfour);
imageViewFive = (ImageView) convertView.findViewById(R.id.ratingfive);
textViewReviewCount = (TextView) convertView.findViewById(R.id.reviewcount);
} else {
descriptionTextView = (TextView) convertView.findViewById(R.id.tv_desc);
oldPriceTextView = (TextView) convertView.findViewById(R.id.tv_old_price);
newPriceTextView = (TextView) convertView.findViewById(R.id.tv_new_price);
stokHabisTextView = (TextView) convertView.findViewById(R.id.tv_out_of_stock);
cicilanTextView = (TextView) convertView.findViewById(R.id.tv_installment);
dividerGridTextView = (TextView) convertView.findViewById(R.id.divider_grid);
imageView = (ImageView) convertView.findViewById(R.id.image);
linearLayout = (LinearLayout) convertView.findViewById(R.id.product_rating);
imageViewOne = (ImageView) convertView.findViewById(R.id.ratingone);
imageViewTwo = (ImageView) convertView.findViewById(R.id.ratingtwo);
imageViewThree = (ImageView) convertView.findViewById(R.id.ratingthree);
imageViewFour = (ImageView) convertView.findViewById(R.id.ratingfour);
imageViewFive = (ImageView) convertView.findViewById(R.id.ratingfive);
textViewReviewCount = (TextView) convertView.findViewById(R.id.reviewcount);
relative = (LinearLayout) convertView.findViewById(R.id.relative);
linearData = (LinearLayout) convertView.findViewById(R.id.linear_data);
}
parentLinearLayout = (LinearLayout) convertView.findViewById(R.id.parentlayoutid);
} else {
categoriesSuggestionLayout = (LinearLayout) convertView.findViewById(R.id.ll_suggest_c2);
categoriesSuggestionTitle = (TextView) convertView.findViewById(R.id.title1);
closeCategoriesSuggestion = (ImageView) convertView.findViewById(R.id.imageView3);
suggestionRelativeLayout =
(RelativeLayout) convertView.findViewById(R.id.suggestion_layout);
}
}
}
public boolean isFashionPart() {
return isFashionPart;
}
public void setFashionPart(boolean isFashionPart) {
this.isFashionPart = isFashionPart;
}
public String getSearch() {
return search;
}
public void setSearch(String search) {
this.search = search;
}
public Activity getActivity() {
return activity;
}
public void setActivity(Activity activity) {
this.activity = activity;
}
public void setScreenResolution(int width, int height) {
screenWidth = width;
screenHeight = height;
}
public void setGravityCenter(TextView... views) {
for (TextView view : views)
view.setGravity(Gravity.CENTER_HORIZONTAL);
}
public int getNumFound() {
return numFound;
}
public void setNumFound(int numFound) {
this.numFound = numFound;
}
public interface OnClick {
void clickListener(String categoryName);
View generateView(String categoryName);
}
}
// This is my recycleview xml code
<android.support.v7.widget.RecyclerView
android:visibility="gone"
android:layout_marginTop="50dp"
android:id="#+id/gridview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f4f4f4"/>

Related Links

How can I fix the space between the navigationbar and actionbar?
Android app start update with cordova-webintent and force stop
Blueprint view nor the constraints are now visible in Android Studio design view
Add user accessible files-Android
ToggleButton changes state when switching fragments
How to send JSON string from arduino to android device in terms of response and then decode the string on the android application?
Is it possible to set link layer encryption and pairing mechanisms for Bluetooth in Android app
Appcelerator Android build fails while running dexer
What is the proper URL to use when loading a gif from Imgur to use in Glide?
Zooming in on View (CameraPreview) without changing its size?
How to find source of a permission in Unity Android
Issue loading resources when app is not running
I can not see my relative layout as before
Android - Implementing a means to get 'real' time in offline apps
How to accept android library licenses automatically from command line?
How to integrate refer and earn in android

Categories

HOME
assembly
oracle12c
hyperlink
eslint
jmx
3d
numbers
components
jelastic
jwplayer
vscode-extensions
dojo
hugo
jquery-ui
teechart
categorical-data
minecraft-forge
endeca
mel
opengl-es-3.0
xcodebuild
google-form
supervisor
job-scheduling
easyphp
template-engine
replication
ksh
jquery-ias
libigl
aggregation
ms-access-2003
database-comparison
code-snippets
openwhisk
joomla2.5
navigator
xajax
openerp-7
google-earth-engine
android-augmented-reality
verifiable-c
linq-to-objects
dbnull
file-sharing
clang++
rfc3339
getchar
ntvs
term
payara-micro
stdmap
flac
objectscript
mathcad
shinobi
swingworker
choice
rocks
preprocessor
qtplugin
mongodb-php
beamer
scaffolding
lean
angular-ui-typeahead
ikiwiki
exim4
vhosts
sciruby
java-money
themoviedb-api
dllimport
doctype
haskell-warp
dnssec
google-refine
mass-assignment
delayed-execution
android-cookiemanager
ghcjs
iso-prolog
raygun
unix-socket
ora-00904
alternate
jquery-slider
buffering
file-not-found
amslidemenu
eclipse-kepler
away3d
resource-management
device-width
thttpd
jsr286
convention
umra
clrstoredprocedure
mtu
timertask
build-environment

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App