RecyclerAdapter is creating multiple view back to back











up vote
0
down vote

favorite












I am using recyclerview to display images in cardview. When I load images from the url. It loads well from first time but when It loads for second time it is not displayed properly.



This is how it is loaded second time



How to fix it? Here is the code



override fun getItemCount(): Int {

dataList = FlickrDBOperation.dataArray
if (dataList!!.isEmpty())
return 0

Log.e("count",dataList!!.size.toString())
return dataList!!.size

}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {

var itemView: View = LayoutInflater.from(parent.context).inflate(R.layout.imagelist_row,parent,false)
var viewHolder: FlickrAdapter.Holder = FlickrAdapter.Holder(itemView)


return viewHolder

}

override fun onBindViewHolder(holder: Holder, position: Int) {

holder.image_name.text = dataList!!.get(position).name
Picasso.with(context).load(dataList!!.get(position).preUrl).into(holder.row_image)

}


class Holder(itemView: View?) : RecyclerView.ViewHolder(itemView) {

val row_image: ImageView
val image_name: TextView
init {
row_image = itemView!!.findViewById<ImageView>(R.id.row_image)
image_name = itemView!!.findViewById<TextView>(R.id.image_name)
}

}









share|improve this question






















  • Does the dataArray from dataList change from time to time? Cause getItemCount() is called a lot and maybe the bug gets in there somehow.
    – CodeRed
    Nov 8 at 20:03










  • No it is filled once only when fragment is created
    – Abhishek Borikar
    Nov 8 at 20:08















up vote
0
down vote

favorite












I am using recyclerview to display images in cardview. When I load images from the url. It loads well from first time but when It loads for second time it is not displayed properly.



This is how it is loaded second time



How to fix it? Here is the code



override fun getItemCount(): Int {

dataList = FlickrDBOperation.dataArray
if (dataList!!.isEmpty())
return 0

Log.e("count",dataList!!.size.toString())
return dataList!!.size

}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {

var itemView: View = LayoutInflater.from(parent.context).inflate(R.layout.imagelist_row,parent,false)
var viewHolder: FlickrAdapter.Holder = FlickrAdapter.Holder(itemView)


return viewHolder

}

override fun onBindViewHolder(holder: Holder, position: Int) {

holder.image_name.text = dataList!!.get(position).name
Picasso.with(context).load(dataList!!.get(position).preUrl).into(holder.row_image)

}


class Holder(itemView: View?) : RecyclerView.ViewHolder(itemView) {

val row_image: ImageView
val image_name: TextView
init {
row_image = itemView!!.findViewById<ImageView>(R.id.row_image)
image_name = itemView!!.findViewById<TextView>(R.id.image_name)
}

}









share|improve this question






















  • Does the dataArray from dataList change from time to time? Cause getItemCount() is called a lot and maybe the bug gets in there somehow.
    – CodeRed
    Nov 8 at 20:03










  • No it is filled once only when fragment is created
    – Abhishek Borikar
    Nov 8 at 20:08













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using recyclerview to display images in cardview. When I load images from the url. It loads well from first time but when It loads for second time it is not displayed properly.



This is how it is loaded second time



How to fix it? Here is the code



override fun getItemCount(): Int {

dataList = FlickrDBOperation.dataArray
if (dataList!!.isEmpty())
return 0

Log.e("count",dataList!!.size.toString())
return dataList!!.size

}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {

var itemView: View = LayoutInflater.from(parent.context).inflate(R.layout.imagelist_row,parent,false)
var viewHolder: FlickrAdapter.Holder = FlickrAdapter.Holder(itemView)


return viewHolder

}

override fun onBindViewHolder(holder: Holder, position: Int) {

holder.image_name.text = dataList!!.get(position).name
Picasso.with(context).load(dataList!!.get(position).preUrl).into(holder.row_image)

}


class Holder(itemView: View?) : RecyclerView.ViewHolder(itemView) {

val row_image: ImageView
val image_name: TextView
init {
row_image = itemView!!.findViewById<ImageView>(R.id.row_image)
image_name = itemView!!.findViewById<TextView>(R.id.image_name)
}

}









share|improve this question













I am using recyclerview to display images in cardview. When I load images from the url. It loads well from first time but when It loads for second time it is not displayed properly.



This is how it is loaded second time



How to fix it? Here is the code



override fun getItemCount(): Int {

dataList = FlickrDBOperation.dataArray
if (dataList!!.isEmpty())
return 0

Log.e("count",dataList!!.size.toString())
return dataList!!.size

}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {

var itemView: View = LayoutInflater.from(parent.context).inflate(R.layout.imagelist_row,parent,false)
var viewHolder: FlickrAdapter.Holder = FlickrAdapter.Holder(itemView)


return viewHolder

}

override fun onBindViewHolder(holder: Holder, position: Int) {

holder.image_name.text = dataList!!.get(position).name
Picasso.with(context).load(dataList!!.get(position).preUrl).into(holder.row_image)

}


class Holder(itemView: View?) : RecyclerView.ViewHolder(itemView) {

val row_image: ImageView
val image_name: TextView
init {
row_image = itemView!!.findViewById<ImageView>(R.id.row_image)
image_name = itemView!!.findViewById<TextView>(R.id.image_name)
}

}






android android-recyclerview recycler-adapter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 19:33









Abhishek Borikar

4419




4419












  • Does the dataArray from dataList change from time to time? Cause getItemCount() is called a lot and maybe the bug gets in there somehow.
    – CodeRed
    Nov 8 at 20:03










  • No it is filled once only when fragment is created
    – Abhishek Borikar
    Nov 8 at 20:08


















  • Does the dataArray from dataList change from time to time? Cause getItemCount() is called a lot and maybe the bug gets in there somehow.
    – CodeRed
    Nov 8 at 20:03










  • No it is filled once only when fragment is created
    – Abhishek Borikar
    Nov 8 at 20:08
















Does the dataArray from dataList change from time to time? Cause getItemCount() is called a lot and maybe the bug gets in there somehow.
– CodeRed
Nov 8 at 20:03




Does the dataArray from dataList change from time to time? Cause getItemCount() is called a lot and maybe the bug gets in there somehow.
– CodeRed
Nov 8 at 20:03












No it is filled once only when fragment is created
– Abhishek Borikar
Nov 8 at 20:08




No it is filled once only when fragment is created
– Abhishek Borikar
Nov 8 at 20:08

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53214919%2frecycleradapter-is-creating-multiple-view-back-to-back%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53214919%2frecycleradapter-is-creating-multiple-view-back-to-back%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Liste der Kulturdenkmale in Wilsdruff

Android Play Services Check