Memory Usage Increases When Scrolling In Recyclerview
I'm using recyclerview to list around 120 layouts that include 1 Imagebutton,1 Textview and 1 Button. The initial memory usage when i first launch the activity that has the recycle
Solution 1:
I don't know if it is a weird bug or if i did something wrong when implementing the Recyclerview but setting viewHolder.setIsRecyclable(false); made my RecyclerView start recycling elements and solved my memory problem.Still so curious to know the reason behind this opposite behavior.
Solution 2:
There are some points to take care:
- No need to make viewHolder class as static.
- Don't add "View.OnClickListener" in "onBindViewHolder". You can use it in viewHolder class. like this
publicclassViewHolderextendsRecyclerView.ViewHolder{
ImageButton emoteButton;
Button optionButton;
TextView text;
publicViewHolder(@NonNull View itemView) {
super(itemView);
emoteButton = itemView.findViewById(R.id.tempimagebutton);
optionButton = itemView.findViewById(R.id.tempbutton);
text = itemView.findViewById(R.id.temptext);
emoteButton.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
DatabaseConstants.INTERSTITIAL_AD_COUNTER++;
commonMethodsInterface.ShowInterstitialAd();
commonMethodsInterface.playEmoteSound(
emoteArray.get(getAdapterPosition()));
}
});
optionButton.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
DatabaseConstants.INTERSTITIAL_AD_COUNTER++;
commonMethodsInterface.ShowInterstitialAd();
commonMethodsInterface.ShowDialog(
emoteArray.get(getAdapterPosition()));
}
});
}
}
Post a Comment for "Memory Usage Increases When Scrolling In Recyclerview"