Android, RecyclerView: Async Loading causes items to double
up vote
0
down vote
favorite
In my app, I have a RecyclerView
containing (on my phone) about 700 song titles with band names. Nothing too crazy, but reloading this all on the UI thread caused a little lag. I decided to do the loading in an Asynctask, away from the UI thread. This is what it looks like:
public class PhotoAlbumAdapter : RecyclerView.Adapter
{
public List<MP3objectSmall> mp3Obj;
Context ctx;
Activity act;
MediaMetadataRetriever reader;
DataBase db;
List<SeekObj> seekObj;
Typeface tf;
AudioManager audioManager;
public PhotoAlbumAdapter(List<MP3objectSmall> mp3Obj, Context ctx, DataBase db, List<SeekObj> seekObj, AudioManager audioManager, Activity act)
{
this.mp3Obj = mp3Obj;
this.ctx = ctx;
this.db = db;
this.seekObj = seekObj;
this.act = act;
this.audioManager = audioManager;
reader = new MediaMetadataRetriever();
tf = Typeface.CreateFromAsset(ctx.Assets, "Baiti.ttf");
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
View itemView = LayoutInflater.From(parent.Context).
Inflate(Resource.Layout.CardView, parent, false);
PhotoViewHolder vh = new PhotoViewHolder(itemView, mp3Obj, act, reader, db, seekObj, audioManager, ctx);
return vh;
}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
PhotoViewHolder vh = holder as PhotoViewHolder;
SetContent(vh, position);
}
private async void SetContent(PhotoViewHolder vh, int position)
{
await SetContentAsync(vh, position);
}
public override int ItemCount
{
get
{
if (mp3Obj != null)
{
return mp3Obj.Count();
}
else
return 0;
}
}
private async Task SetContentAsync(PhotoViewHolder vh, int position)
{
string SongName = "";
string ArtistName = "";
await Task.Run(() =>
{
try
{
reader.SetDataSource(mp3Obj[position].Mp3Uri);
}
catch
{
}
SongName = reader.ExtractMetadata(MediaMetadataRetriever.MetadataKeyTitle);
ArtistName = reader.ExtractMetadata(MediaMetadataRetriever.MetadataKeyArtist);
});
((Activity)ctx).RunOnUiThread(() =>
{
vh.SongName.SetTypeface(tf, TypefaceStyle.Normal);
vh.AristName.SetTypeface(tf, TypefaceStyle.Normal);
vh.SongName.Text = SongName;
vh.AristName.Text = ArtistName;
});
}
}
This did infact smooth the overall performance up quite a lot but caused some weird side effect:
When I scrolling down the list fast and then stop it appruptley I see the same song 2-3 times in a row. Only one of those items is the song itself, the others are different songs but with the wrong song and artist name on top of them.
If I now scroll up just ever so slightly that the doubling items are out just off the screen and then scroll back the RecyclerView
seems to have corrected itself and the doubled or sometimes tripled items are gone.
This issue only occurs since I moved the loading into an Async-task. Did I maybe do something wrong here?
android android-recyclerview
add a comment |
up vote
0
down vote
favorite
In my app, I have a RecyclerView
containing (on my phone) about 700 song titles with band names. Nothing too crazy, but reloading this all on the UI thread caused a little lag. I decided to do the loading in an Asynctask, away from the UI thread. This is what it looks like:
public class PhotoAlbumAdapter : RecyclerView.Adapter
{
public List<MP3objectSmall> mp3Obj;
Context ctx;
Activity act;
MediaMetadataRetriever reader;
DataBase db;
List<SeekObj> seekObj;
Typeface tf;
AudioManager audioManager;
public PhotoAlbumAdapter(List<MP3objectSmall> mp3Obj, Context ctx, DataBase db, List<SeekObj> seekObj, AudioManager audioManager, Activity act)
{
this.mp3Obj = mp3Obj;
this.ctx = ctx;
this.db = db;
this.seekObj = seekObj;
this.act = act;
this.audioManager = audioManager;
reader = new MediaMetadataRetriever();
tf = Typeface.CreateFromAsset(ctx.Assets, "Baiti.ttf");
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
View itemView = LayoutInflater.From(parent.Context).
Inflate(Resource.Layout.CardView, parent, false);
PhotoViewHolder vh = new PhotoViewHolder(itemView, mp3Obj, act, reader, db, seekObj, audioManager, ctx);
return vh;
}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
PhotoViewHolder vh = holder as PhotoViewHolder;
SetContent(vh, position);
}
private async void SetContent(PhotoViewHolder vh, int position)
{
await SetContentAsync(vh, position);
}
public override int ItemCount
{
get
{
if (mp3Obj != null)
{
return mp3Obj.Count();
}
else
return 0;
}
}
private async Task SetContentAsync(PhotoViewHolder vh, int position)
{
string SongName = "";
string ArtistName = "";
await Task.Run(() =>
{
try
{
reader.SetDataSource(mp3Obj[position].Mp3Uri);
}
catch
{
}
SongName = reader.ExtractMetadata(MediaMetadataRetriever.MetadataKeyTitle);
ArtistName = reader.ExtractMetadata(MediaMetadataRetriever.MetadataKeyArtist);
});
((Activity)ctx).RunOnUiThread(() =>
{
vh.SongName.SetTypeface(tf, TypefaceStyle.Normal);
vh.AristName.SetTypeface(tf, TypefaceStyle.Normal);
vh.SongName.Text = SongName;
vh.AristName.Text = ArtistName;
});
}
}
This did infact smooth the overall performance up quite a lot but caused some weird side effect:
When I scrolling down the list fast and then stop it appruptley I see the same song 2-3 times in a row. Only one of those items is the song itself, the others are different songs but with the wrong song and artist name on top of them.
If I now scroll up just ever so slightly that the doubling items are out just off the screen and then scroll back the RecyclerView
seems to have corrected itself and the doubled or sometimes tripled items are gone.
This issue only occurs since I moved the loading into an Async-task. Did I maybe do something wrong here?
android android-recyclerview
I did not read your code completely. But if you are loading an Image in an ImageView. Then consider using a Image Loading Library like Picasso.
– Rohit Singh
Nov 21 at 13:35
no imageview loading. just doubled items :)
– Innomotion Media
Nov 21 at 13:48
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
In my app, I have a RecyclerView
containing (on my phone) about 700 song titles with band names. Nothing too crazy, but reloading this all on the UI thread caused a little lag. I decided to do the loading in an Asynctask, away from the UI thread. This is what it looks like:
public class PhotoAlbumAdapter : RecyclerView.Adapter
{
public List<MP3objectSmall> mp3Obj;
Context ctx;
Activity act;
MediaMetadataRetriever reader;
DataBase db;
List<SeekObj> seekObj;
Typeface tf;
AudioManager audioManager;
public PhotoAlbumAdapter(List<MP3objectSmall> mp3Obj, Context ctx, DataBase db, List<SeekObj> seekObj, AudioManager audioManager, Activity act)
{
this.mp3Obj = mp3Obj;
this.ctx = ctx;
this.db = db;
this.seekObj = seekObj;
this.act = act;
this.audioManager = audioManager;
reader = new MediaMetadataRetriever();
tf = Typeface.CreateFromAsset(ctx.Assets, "Baiti.ttf");
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
View itemView = LayoutInflater.From(parent.Context).
Inflate(Resource.Layout.CardView, parent, false);
PhotoViewHolder vh = new PhotoViewHolder(itemView, mp3Obj, act, reader, db, seekObj, audioManager, ctx);
return vh;
}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
PhotoViewHolder vh = holder as PhotoViewHolder;
SetContent(vh, position);
}
private async void SetContent(PhotoViewHolder vh, int position)
{
await SetContentAsync(vh, position);
}
public override int ItemCount
{
get
{
if (mp3Obj != null)
{
return mp3Obj.Count();
}
else
return 0;
}
}
private async Task SetContentAsync(PhotoViewHolder vh, int position)
{
string SongName = "";
string ArtistName = "";
await Task.Run(() =>
{
try
{
reader.SetDataSource(mp3Obj[position].Mp3Uri);
}
catch
{
}
SongName = reader.ExtractMetadata(MediaMetadataRetriever.MetadataKeyTitle);
ArtistName = reader.ExtractMetadata(MediaMetadataRetriever.MetadataKeyArtist);
});
((Activity)ctx).RunOnUiThread(() =>
{
vh.SongName.SetTypeface(tf, TypefaceStyle.Normal);
vh.AristName.SetTypeface(tf, TypefaceStyle.Normal);
vh.SongName.Text = SongName;
vh.AristName.Text = ArtistName;
});
}
}
This did infact smooth the overall performance up quite a lot but caused some weird side effect:
When I scrolling down the list fast and then stop it appruptley I see the same song 2-3 times in a row. Only one of those items is the song itself, the others are different songs but with the wrong song and artist name on top of them.
If I now scroll up just ever so slightly that the doubling items are out just off the screen and then scroll back the RecyclerView
seems to have corrected itself and the doubled or sometimes tripled items are gone.
This issue only occurs since I moved the loading into an Async-task. Did I maybe do something wrong here?
android android-recyclerview
In my app, I have a RecyclerView
containing (on my phone) about 700 song titles with band names. Nothing too crazy, but reloading this all on the UI thread caused a little lag. I decided to do the loading in an Asynctask, away from the UI thread. This is what it looks like:
public class PhotoAlbumAdapter : RecyclerView.Adapter
{
public List<MP3objectSmall> mp3Obj;
Context ctx;
Activity act;
MediaMetadataRetriever reader;
DataBase db;
List<SeekObj> seekObj;
Typeface tf;
AudioManager audioManager;
public PhotoAlbumAdapter(List<MP3objectSmall> mp3Obj, Context ctx, DataBase db, List<SeekObj> seekObj, AudioManager audioManager, Activity act)
{
this.mp3Obj = mp3Obj;
this.ctx = ctx;
this.db = db;
this.seekObj = seekObj;
this.act = act;
this.audioManager = audioManager;
reader = new MediaMetadataRetriever();
tf = Typeface.CreateFromAsset(ctx.Assets, "Baiti.ttf");
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
View itemView = LayoutInflater.From(parent.Context).
Inflate(Resource.Layout.CardView, parent, false);
PhotoViewHolder vh = new PhotoViewHolder(itemView, mp3Obj, act, reader, db, seekObj, audioManager, ctx);
return vh;
}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
PhotoViewHolder vh = holder as PhotoViewHolder;
SetContent(vh, position);
}
private async void SetContent(PhotoViewHolder vh, int position)
{
await SetContentAsync(vh, position);
}
public override int ItemCount
{
get
{
if (mp3Obj != null)
{
return mp3Obj.Count();
}
else
return 0;
}
}
private async Task SetContentAsync(PhotoViewHolder vh, int position)
{
string SongName = "";
string ArtistName = "";
await Task.Run(() =>
{
try
{
reader.SetDataSource(mp3Obj[position].Mp3Uri);
}
catch
{
}
SongName = reader.ExtractMetadata(MediaMetadataRetriever.MetadataKeyTitle);
ArtistName = reader.ExtractMetadata(MediaMetadataRetriever.MetadataKeyArtist);
});
((Activity)ctx).RunOnUiThread(() =>
{
vh.SongName.SetTypeface(tf, TypefaceStyle.Normal);
vh.AristName.SetTypeface(tf, TypefaceStyle.Normal);
vh.SongName.Text = SongName;
vh.AristName.Text = ArtistName;
});
}
}
This did infact smooth the overall performance up quite a lot but caused some weird side effect:
When I scrolling down the list fast and then stop it appruptley I see the same song 2-3 times in a row. Only one of those items is the song itself, the others are different songs but with the wrong song and artist name on top of them.
If I now scroll up just ever so slightly that the doubling items are out just off the screen and then scroll back the RecyclerView
seems to have corrected itself and the doubled or sometimes tripled items are gone.
This issue only occurs since I moved the loading into an Async-task. Did I maybe do something wrong here?
android android-recyclerview
android android-recyclerview
edited Nov 22 at 5:53
Ali Khaki
6971418
6971418
asked Nov 21 at 13:22
Innomotion Media
266
266
I did not read your code completely. But if you are loading an Image in an ImageView. Then consider using a Image Loading Library like Picasso.
– Rohit Singh
Nov 21 at 13:35
no imageview loading. just doubled items :)
– Innomotion Media
Nov 21 at 13:48
add a comment |
I did not read your code completely. But if you are loading an Image in an ImageView. Then consider using a Image Loading Library like Picasso.
– Rohit Singh
Nov 21 at 13:35
no imageview loading. just doubled items :)
– Innomotion Media
Nov 21 at 13:48
I did not read your code completely. But if you are loading an Image in an ImageView. Then consider using a Image Loading Library like Picasso.
– Rohit Singh
Nov 21 at 13:35
I did not read your code completely. But if you are loading an Image in an ImageView. Then consider using a Image Loading Library like Picasso.
– Rohit Singh
Nov 21 at 13:35
no imageview loading. just doubled items :)
– Innomotion Media
Nov 21 at 13:48
no imageview loading. just doubled items :)
– Innomotion Media
Nov 21 at 13:48
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
I think the point here is to keep references of the viewHolder
.
I would suggest you to try an approach like that:
public class PhotoViewHolder extends RecyclerView.ViewHolder {
private TextView tvSongName;
public PhotoViewHolder(View v) {
super(v);
//initialize here views; ie
//this.tvSongName = v.findViewById(R.id.tvSongName);
}
public void initializeAsync(int position) {
Handler mHandler = new Handler();
new Thread(new Runnable() {
String songName, otherStuff;
@Override
public void run () {
// here we are async.
// Retrieve here your song informations, ie:
//object myRetrievedObject = getSongInfoBasedOnPositionSomeHow();
//songName = myRetrievedObject.retrievedSongName;
//otherStuff = myRetrievedObject.retrievedOtherStuffs;
mHandler.post(new Runnable() {
@Override
public void run () {
// make operation on UI
tvSongName.setText(songName);
//...
//...
}
});
}
}).start();
}
}
And call this like:
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
PhotoViewHolder vh = holder as PhotoViewHolder;
vh.initializeAsync(position);
}
Please consider that I wrote that without the compiler so it might be not perfect, let me know in any case.
Hope this helps!
hey thank you for the effort, you dont have this in any chance in c#? :)
– Innomotion Media
Nov 21 at 14:29
@InnomotionMedia you should consider changing the tag in the question, if not specified android is java by default :) It's really similar; I'm not an expert of xamarin so unfortunatly I can't help you with c#
– Pier Giorgio Misley
Nov 21 at 15:07
I shall give it a go soon :)
– Innomotion Media
Nov 21 at 15:20
add a comment |
up vote
0
down vote
I think the arraylist is getting populated twice.so Just before loading arraylist once again in your activity class use yourarraylistname.clear(); to clear the arraylist and then load the data next tym.So whenever you populate the arraylist again it will first get cleared then load the data once again.
Sorry, I dont really understand. What do you mean? :)
– Innomotion Media
Nov 22 at 10:17
@InnomotionMedia please check my updated answer , hope you understand.
– Suvarthee Chakravarti
Nov 22 at 12:18
thank you. however I can see from my debugger that my list is just fine. it must be the recycler view that confuses the views ...
– Innomotion Media
Nov 22 at 12:32
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
I think the point here is to keep references of the viewHolder
.
I would suggest you to try an approach like that:
public class PhotoViewHolder extends RecyclerView.ViewHolder {
private TextView tvSongName;
public PhotoViewHolder(View v) {
super(v);
//initialize here views; ie
//this.tvSongName = v.findViewById(R.id.tvSongName);
}
public void initializeAsync(int position) {
Handler mHandler = new Handler();
new Thread(new Runnable() {
String songName, otherStuff;
@Override
public void run () {
// here we are async.
// Retrieve here your song informations, ie:
//object myRetrievedObject = getSongInfoBasedOnPositionSomeHow();
//songName = myRetrievedObject.retrievedSongName;
//otherStuff = myRetrievedObject.retrievedOtherStuffs;
mHandler.post(new Runnable() {
@Override
public void run () {
// make operation on UI
tvSongName.setText(songName);
//...
//...
}
});
}
}).start();
}
}
And call this like:
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
PhotoViewHolder vh = holder as PhotoViewHolder;
vh.initializeAsync(position);
}
Please consider that I wrote that without the compiler so it might be not perfect, let me know in any case.
Hope this helps!
hey thank you for the effort, you dont have this in any chance in c#? :)
– Innomotion Media
Nov 21 at 14:29
@InnomotionMedia you should consider changing the tag in the question, if not specified android is java by default :) It's really similar; I'm not an expert of xamarin so unfortunatly I can't help you with c#
– Pier Giorgio Misley
Nov 21 at 15:07
I shall give it a go soon :)
– Innomotion Media
Nov 21 at 15:20
add a comment |
up vote
1
down vote
I think the point here is to keep references of the viewHolder
.
I would suggest you to try an approach like that:
public class PhotoViewHolder extends RecyclerView.ViewHolder {
private TextView tvSongName;
public PhotoViewHolder(View v) {
super(v);
//initialize here views; ie
//this.tvSongName = v.findViewById(R.id.tvSongName);
}
public void initializeAsync(int position) {
Handler mHandler = new Handler();
new Thread(new Runnable() {
String songName, otherStuff;
@Override
public void run () {
// here we are async.
// Retrieve here your song informations, ie:
//object myRetrievedObject = getSongInfoBasedOnPositionSomeHow();
//songName = myRetrievedObject.retrievedSongName;
//otherStuff = myRetrievedObject.retrievedOtherStuffs;
mHandler.post(new Runnable() {
@Override
public void run () {
// make operation on UI
tvSongName.setText(songName);
//...
//...
}
});
}
}).start();
}
}
And call this like:
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
PhotoViewHolder vh = holder as PhotoViewHolder;
vh.initializeAsync(position);
}
Please consider that I wrote that without the compiler so it might be not perfect, let me know in any case.
Hope this helps!
hey thank you for the effort, you dont have this in any chance in c#? :)
– Innomotion Media
Nov 21 at 14:29
@InnomotionMedia you should consider changing the tag in the question, if not specified android is java by default :) It's really similar; I'm not an expert of xamarin so unfortunatly I can't help you with c#
– Pier Giorgio Misley
Nov 21 at 15:07
I shall give it a go soon :)
– Innomotion Media
Nov 21 at 15:20
add a comment |
up vote
1
down vote
up vote
1
down vote
I think the point here is to keep references of the viewHolder
.
I would suggest you to try an approach like that:
public class PhotoViewHolder extends RecyclerView.ViewHolder {
private TextView tvSongName;
public PhotoViewHolder(View v) {
super(v);
//initialize here views; ie
//this.tvSongName = v.findViewById(R.id.tvSongName);
}
public void initializeAsync(int position) {
Handler mHandler = new Handler();
new Thread(new Runnable() {
String songName, otherStuff;
@Override
public void run () {
// here we are async.
// Retrieve here your song informations, ie:
//object myRetrievedObject = getSongInfoBasedOnPositionSomeHow();
//songName = myRetrievedObject.retrievedSongName;
//otherStuff = myRetrievedObject.retrievedOtherStuffs;
mHandler.post(new Runnable() {
@Override
public void run () {
// make operation on UI
tvSongName.setText(songName);
//...
//...
}
});
}
}).start();
}
}
And call this like:
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
PhotoViewHolder vh = holder as PhotoViewHolder;
vh.initializeAsync(position);
}
Please consider that I wrote that without the compiler so it might be not perfect, let me know in any case.
Hope this helps!
I think the point here is to keep references of the viewHolder
.
I would suggest you to try an approach like that:
public class PhotoViewHolder extends RecyclerView.ViewHolder {
private TextView tvSongName;
public PhotoViewHolder(View v) {
super(v);
//initialize here views; ie
//this.tvSongName = v.findViewById(R.id.tvSongName);
}
public void initializeAsync(int position) {
Handler mHandler = new Handler();
new Thread(new Runnable() {
String songName, otherStuff;
@Override
public void run () {
// here we are async.
// Retrieve here your song informations, ie:
//object myRetrievedObject = getSongInfoBasedOnPositionSomeHow();
//songName = myRetrievedObject.retrievedSongName;
//otherStuff = myRetrievedObject.retrievedOtherStuffs;
mHandler.post(new Runnable() {
@Override
public void run () {
// make operation on UI
tvSongName.setText(songName);
//...
//...
}
});
}
}).start();
}
}
And call this like:
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
PhotoViewHolder vh = holder as PhotoViewHolder;
vh.initializeAsync(position);
}
Please consider that I wrote that without the compiler so it might be not perfect, let me know in any case.
Hope this helps!
answered Nov 21 at 14:12
Pier Giorgio Misley
3,25821339
3,25821339
hey thank you for the effort, you dont have this in any chance in c#? :)
– Innomotion Media
Nov 21 at 14:29
@InnomotionMedia you should consider changing the tag in the question, if not specified android is java by default :) It's really similar; I'm not an expert of xamarin so unfortunatly I can't help you with c#
– Pier Giorgio Misley
Nov 21 at 15:07
I shall give it a go soon :)
– Innomotion Media
Nov 21 at 15:20
add a comment |
hey thank you for the effort, you dont have this in any chance in c#? :)
– Innomotion Media
Nov 21 at 14:29
@InnomotionMedia you should consider changing the tag in the question, if not specified android is java by default :) It's really similar; I'm not an expert of xamarin so unfortunatly I can't help you with c#
– Pier Giorgio Misley
Nov 21 at 15:07
I shall give it a go soon :)
– Innomotion Media
Nov 21 at 15:20
hey thank you for the effort, you dont have this in any chance in c#? :)
– Innomotion Media
Nov 21 at 14:29
hey thank you for the effort, you dont have this in any chance in c#? :)
– Innomotion Media
Nov 21 at 14:29
@InnomotionMedia you should consider changing the tag in the question, if not specified android is java by default :) It's really similar; I'm not an expert of xamarin so unfortunatly I can't help you with c#
– Pier Giorgio Misley
Nov 21 at 15:07
@InnomotionMedia you should consider changing the tag in the question, if not specified android is java by default :) It's really similar; I'm not an expert of xamarin so unfortunatly I can't help you with c#
– Pier Giorgio Misley
Nov 21 at 15:07
I shall give it a go soon :)
– Innomotion Media
Nov 21 at 15:20
I shall give it a go soon :)
– Innomotion Media
Nov 21 at 15:20
add a comment |
up vote
0
down vote
I think the arraylist is getting populated twice.so Just before loading arraylist once again in your activity class use yourarraylistname.clear(); to clear the arraylist and then load the data next tym.So whenever you populate the arraylist again it will first get cleared then load the data once again.
Sorry, I dont really understand. What do you mean? :)
– Innomotion Media
Nov 22 at 10:17
@InnomotionMedia please check my updated answer , hope you understand.
– Suvarthee Chakravarti
Nov 22 at 12:18
thank you. however I can see from my debugger that my list is just fine. it must be the recycler view that confuses the views ...
– Innomotion Media
Nov 22 at 12:32
add a comment |
up vote
0
down vote
I think the arraylist is getting populated twice.so Just before loading arraylist once again in your activity class use yourarraylistname.clear(); to clear the arraylist and then load the data next tym.So whenever you populate the arraylist again it will first get cleared then load the data once again.
Sorry, I dont really understand. What do you mean? :)
– Innomotion Media
Nov 22 at 10:17
@InnomotionMedia please check my updated answer , hope you understand.
– Suvarthee Chakravarti
Nov 22 at 12:18
thank you. however I can see from my debugger that my list is just fine. it must be the recycler view that confuses the views ...
– Innomotion Media
Nov 22 at 12:32
add a comment |
up vote
0
down vote
up vote
0
down vote
I think the arraylist is getting populated twice.so Just before loading arraylist once again in your activity class use yourarraylistname.clear(); to clear the arraylist and then load the data next tym.So whenever you populate the arraylist again it will first get cleared then load the data once again.
I think the arraylist is getting populated twice.so Just before loading arraylist once again in your activity class use yourarraylistname.clear(); to clear the arraylist and then load the data next tym.So whenever you populate the arraylist again it will first get cleared then load the data once again.
edited Nov 22 at 12:17
answered Nov 22 at 6:39
Suvarthee Chakravarti
11
11
Sorry, I dont really understand. What do you mean? :)
– Innomotion Media
Nov 22 at 10:17
@InnomotionMedia please check my updated answer , hope you understand.
– Suvarthee Chakravarti
Nov 22 at 12:18
thank you. however I can see from my debugger that my list is just fine. it must be the recycler view that confuses the views ...
– Innomotion Media
Nov 22 at 12:32
add a comment |
Sorry, I dont really understand. What do you mean? :)
– Innomotion Media
Nov 22 at 10:17
@InnomotionMedia please check my updated answer , hope you understand.
– Suvarthee Chakravarti
Nov 22 at 12:18
thank you. however I can see from my debugger that my list is just fine. it must be the recycler view that confuses the views ...
– Innomotion Media
Nov 22 at 12:32
Sorry, I dont really understand. What do you mean? :)
– Innomotion Media
Nov 22 at 10:17
Sorry, I dont really understand. What do you mean? :)
– Innomotion Media
Nov 22 at 10:17
@InnomotionMedia please check my updated answer , hope you understand.
– Suvarthee Chakravarti
Nov 22 at 12:18
@InnomotionMedia please check my updated answer , hope you understand.
– Suvarthee Chakravarti
Nov 22 at 12:18
thank you. however I can see from my debugger that my list is just fine. it must be the recycler view that confuses the views ...
– Innomotion Media
Nov 22 at 12:32
thank you. however I can see from my debugger that my list is just fine. it must be the recycler view that confuses the views ...
– Innomotion Media
Nov 22 at 12:32
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413002%2fandroid-recyclerview-async-loading-causes-items-to-double%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
I did not read your code completely. But if you are loading an Image in an ImageView. Then consider using a Image Loading Library like Picasso.
– Rohit Singh
Nov 21 at 13:35
no imageview loading. just doubled items :)
– Innomotion Media
Nov 21 at 13:48