Android, RecyclerView: Async Loading causes items to double












0















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?










share|improve this question

























  • 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 '18 at 13:35











  • no imageview loading. just doubled items :)

    – Innomotion Media
    Nov 21 '18 at 13:48
















0















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?










share|improve this question

























  • 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 '18 at 13:35











  • no imageview loading. just doubled items :)

    – Innomotion Media
    Nov 21 '18 at 13:48














0












0








0








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 5:53









Ali Khaki

8921519




8921519










asked Nov 21 '18 at 13:22









Innomotion MediaInnomotion 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 '18 at 13:35











  • no imageview loading. just doubled items :)

    – Innomotion Media
    Nov 21 '18 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 '18 at 13:35











  • no imageview loading. just doubled items :)

    – Innomotion Media
    Nov 21 '18 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 '18 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 '18 at 13:35













no imageview loading. just doubled items :)

– Innomotion Media
Nov 21 '18 at 13:48





no imageview loading. just doubled items :)

– Innomotion Media
Nov 21 '18 at 13:48












2 Answers
2






active

oldest

votes


















1














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!






share|improve this answer
























  • hey thank you for the effort, you dont have this in any chance in c#? :)

    – Innomotion Media
    Nov 21 '18 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 '18 at 15:07











  • I shall give it a go soon :)

    – Innomotion Media
    Nov 21 '18 at 15:20



















0














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.






share|improve this answer


























  • Sorry, I dont really understand. What do you mean? :)

    – Innomotion Media
    Nov 22 '18 at 10:17











  • @InnomotionMedia please check my updated answer , hope you understand.

    – Suvarthee Chakravarti
    Nov 22 '18 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 '18 at 12:32











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',
autoActivateHeartbeat: false,
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%2f53413002%2fandroid-recyclerview-async-loading-causes-items-to-double%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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!






share|improve this answer
























  • hey thank you for the effort, you dont have this in any chance in c#? :)

    – Innomotion Media
    Nov 21 '18 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 '18 at 15:07











  • I shall give it a go soon :)

    – Innomotion Media
    Nov 21 '18 at 15:20
















1














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!






share|improve this answer
























  • hey thank you for the effort, you dont have this in any chance in c#? :)

    – Innomotion Media
    Nov 21 '18 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 '18 at 15:07











  • I shall give it a go soon :)

    – Innomotion Media
    Nov 21 '18 at 15:20














1












1








1







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!






share|improve this answer













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!







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 14:12









Pier Giorgio MisleyPier Giorgio Misley

3,27321440




3,27321440













  • hey thank you for the effort, you dont have this in any chance in c#? :)

    – Innomotion Media
    Nov 21 '18 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 '18 at 15:07











  • I shall give it a go soon :)

    – Innomotion Media
    Nov 21 '18 at 15:20



















  • hey thank you for the effort, you dont have this in any chance in c#? :)

    – Innomotion Media
    Nov 21 '18 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 '18 at 15:07











  • I shall give it a go soon :)

    – Innomotion Media
    Nov 21 '18 at 15:20

















hey thank you for the effort, you dont have this in any chance in c#? :)

– Innomotion Media
Nov 21 '18 at 14:29





hey thank you for the effort, you dont have this in any chance in c#? :)

– Innomotion Media
Nov 21 '18 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 '18 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 '18 at 15:07













I shall give it a go soon :)

– Innomotion Media
Nov 21 '18 at 15:20





I shall give it a go soon :)

– Innomotion Media
Nov 21 '18 at 15:20













0














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.






share|improve this answer


























  • Sorry, I dont really understand. What do you mean? :)

    – Innomotion Media
    Nov 22 '18 at 10:17











  • @InnomotionMedia please check my updated answer , hope you understand.

    – Suvarthee Chakravarti
    Nov 22 '18 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 '18 at 12:32
















0














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.






share|improve this answer


























  • Sorry, I dont really understand. What do you mean? :)

    – Innomotion Media
    Nov 22 '18 at 10:17











  • @InnomotionMedia please check my updated answer , hope you understand.

    – Suvarthee Chakravarti
    Nov 22 '18 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 '18 at 12:32














0












0








0







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 12:17

























answered Nov 22 '18 at 6:39









Suvarthee ChakravartiSuvarthee Chakravarti

11




11













  • Sorry, I dont really understand. What do you mean? :)

    – Innomotion Media
    Nov 22 '18 at 10:17











  • @InnomotionMedia please check my updated answer , hope you understand.

    – Suvarthee Chakravarti
    Nov 22 '18 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 '18 at 12:32



















  • Sorry, I dont really understand. What do you mean? :)

    – Innomotion Media
    Nov 22 '18 at 10:17











  • @InnomotionMedia please check my updated answer , hope you understand.

    – Suvarthee Chakravarti
    Nov 22 '18 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 '18 at 12:32

















Sorry, I dont really understand. What do you mean? :)

– Innomotion Media
Nov 22 '18 at 10:17





Sorry, I dont really understand. What do you mean? :)

– Innomotion Media
Nov 22 '18 at 10:17













@InnomotionMedia please check my updated answer , hope you understand.

– Suvarthee Chakravarti
Nov 22 '18 at 12:18





@InnomotionMedia please check my updated answer , hope you understand.

– Suvarthee Chakravarti
Nov 22 '18 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 '18 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 '18 at 12:32


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy