Multiple viewholder in RecyclerView skips items
I have an adapter which is responsible to read from my local database and display some cardviews, yesterday I added another view in to the mix to handle the admob advertisements. but where it adds an add. it skips one of my database entries.
so what I did was this
int TYPE_POST = 0;
int TYPE_AD = 1;
@Override
public int getItemViewType(int position) {
if ((position % 5) == 0) {
return TYPE_AD;
}
return TYPE_POST;
}
and I have this onBindViewHolder if i change this final dbFeed dbfeed = LemesosAdapter.get(position);
to final dbFeed dbfeed = LemesosAdapter.get(position+1);
the very 1st post wont be skipped . but the second time an advert is added it will be skipped.
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
if (getItemViewType(position) == TYPE_POST) {
// - get element from dataset at this position
// - replace the contents of the view with that element
PostViewHolder postViewHolder = (PostViewHolder)holder;
final dbFeed dbfeed = LemesosAdapter.get(position);
//Animation by yoyo library
YoYo.with(Techniques.BounceIn).playOn(postViewHolder.cardView);
String description;
description = Html.fromHtml(dbfeed.getDescription()).toString().replaceAll("n", "").trim().substring(0, 100).replace((char) 65532, (char) 32).trim() + "...";
postViewHolder.Title.setText(dbfeed.getTitle());
postViewHolder.Description.setText(description);
postViewHolder.Date.setText(dbfeed.getPubDate());
Picasso.with(context).load(dbfeed.getThumbnailUrl()).placeholder(R.drawable.ic_image).into(postViewHolder.Thumbnail);
postViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, NewsDetails.class);
intent.putExtra("ThumbNail", dbfeed.getThumbnailUrl());
intent.putExtra("Link", dbfeed.getThumbnailUrl());
intent.putExtra("Title", dbfeed.getTitle());
intent.putExtra("Description", dbfeed.getDescription());
intent.putExtra("Date", dbfeed.getPubDate());
context.startActivity(intent);
}
});
} else if (getItemViewType(position) == TYPE_AD ) {
}
}
and finally my getItemCount . in here I think is where the solution is. ive seen in this side in other post that I should do the same Modal as I did with my starting one ((itemcount %5) + itemcount) but it does not work
@Override
public int getItemCount() {
return ((LemesosAdapter.size()%5))+LemesosAdapter.size() ;
}
}
what I am missing here?
android android-recyclerview
|
show 2 more comments
I have an adapter which is responsible to read from my local database and display some cardviews, yesterday I added another view in to the mix to handle the admob advertisements. but where it adds an add. it skips one of my database entries.
so what I did was this
int TYPE_POST = 0;
int TYPE_AD = 1;
@Override
public int getItemViewType(int position) {
if ((position % 5) == 0) {
return TYPE_AD;
}
return TYPE_POST;
}
and I have this onBindViewHolder if i change this final dbFeed dbfeed = LemesosAdapter.get(position);
to final dbFeed dbfeed = LemesosAdapter.get(position+1);
the very 1st post wont be skipped . but the second time an advert is added it will be skipped.
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
if (getItemViewType(position) == TYPE_POST) {
// - get element from dataset at this position
// - replace the contents of the view with that element
PostViewHolder postViewHolder = (PostViewHolder)holder;
final dbFeed dbfeed = LemesosAdapter.get(position);
//Animation by yoyo library
YoYo.with(Techniques.BounceIn).playOn(postViewHolder.cardView);
String description;
description = Html.fromHtml(dbfeed.getDescription()).toString().replaceAll("n", "").trim().substring(0, 100).replace((char) 65532, (char) 32).trim() + "...";
postViewHolder.Title.setText(dbfeed.getTitle());
postViewHolder.Description.setText(description);
postViewHolder.Date.setText(dbfeed.getPubDate());
Picasso.with(context).load(dbfeed.getThumbnailUrl()).placeholder(R.drawable.ic_image).into(postViewHolder.Thumbnail);
postViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, NewsDetails.class);
intent.putExtra("ThumbNail", dbfeed.getThumbnailUrl());
intent.putExtra("Link", dbfeed.getThumbnailUrl());
intent.putExtra("Title", dbfeed.getTitle());
intent.putExtra("Description", dbfeed.getDescription());
intent.putExtra("Date", dbfeed.getPubDate());
context.startActivity(intent);
}
});
} else if (getItemViewType(position) == TYPE_AD ) {
}
}
and finally my getItemCount . in here I think is where the solution is. ive seen in this side in other post that I should do the same Modal as I did with my starting one ((itemcount %5) + itemcount) but it does not work
@Override
public int getItemCount() {
return ((LemesosAdapter.size()%5))+LemesosAdapter.size() ;
}
}
what I am missing here?
android android-recyclerview
1
Can you please set item count like below.@Override public int getItemCount() { return (((int) LemesosAdapter.size()/5))+LemesosAdapter.size() ; }
– Mahavir Jain
Nov 23 '18 at 10:59
OMG, I'm not see that %. I see it as /.
– Hello World
Nov 23 '18 at 11:03
@MahavirJain this still skips each 5th position as well
– Demeteor
Nov 23 '18 at 11:05
Also you have to change logic.LemesosAdapter.get(getPosition(position)) fun getPosition(position: Int): Int = (position + (position / 5))
– Mahavir Jain
Nov 23 '18 at 11:41
@MahavirJain what is fun stands for? is it kotlin ?
– Demeteor
Nov 26 '18 at 12:44
|
show 2 more comments
I have an adapter which is responsible to read from my local database and display some cardviews, yesterday I added another view in to the mix to handle the admob advertisements. but where it adds an add. it skips one of my database entries.
so what I did was this
int TYPE_POST = 0;
int TYPE_AD = 1;
@Override
public int getItemViewType(int position) {
if ((position % 5) == 0) {
return TYPE_AD;
}
return TYPE_POST;
}
and I have this onBindViewHolder if i change this final dbFeed dbfeed = LemesosAdapter.get(position);
to final dbFeed dbfeed = LemesosAdapter.get(position+1);
the very 1st post wont be skipped . but the second time an advert is added it will be skipped.
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
if (getItemViewType(position) == TYPE_POST) {
// - get element from dataset at this position
// - replace the contents of the view with that element
PostViewHolder postViewHolder = (PostViewHolder)holder;
final dbFeed dbfeed = LemesosAdapter.get(position);
//Animation by yoyo library
YoYo.with(Techniques.BounceIn).playOn(postViewHolder.cardView);
String description;
description = Html.fromHtml(dbfeed.getDescription()).toString().replaceAll("n", "").trim().substring(0, 100).replace((char) 65532, (char) 32).trim() + "...";
postViewHolder.Title.setText(dbfeed.getTitle());
postViewHolder.Description.setText(description);
postViewHolder.Date.setText(dbfeed.getPubDate());
Picasso.with(context).load(dbfeed.getThumbnailUrl()).placeholder(R.drawable.ic_image).into(postViewHolder.Thumbnail);
postViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, NewsDetails.class);
intent.putExtra("ThumbNail", dbfeed.getThumbnailUrl());
intent.putExtra("Link", dbfeed.getThumbnailUrl());
intent.putExtra("Title", dbfeed.getTitle());
intent.putExtra("Description", dbfeed.getDescription());
intent.putExtra("Date", dbfeed.getPubDate());
context.startActivity(intent);
}
});
} else if (getItemViewType(position) == TYPE_AD ) {
}
}
and finally my getItemCount . in here I think is where the solution is. ive seen in this side in other post that I should do the same Modal as I did with my starting one ((itemcount %5) + itemcount) but it does not work
@Override
public int getItemCount() {
return ((LemesosAdapter.size()%5))+LemesosAdapter.size() ;
}
}
what I am missing here?
android android-recyclerview
I have an adapter which is responsible to read from my local database and display some cardviews, yesterday I added another view in to the mix to handle the admob advertisements. but where it adds an add. it skips one of my database entries.
so what I did was this
int TYPE_POST = 0;
int TYPE_AD = 1;
@Override
public int getItemViewType(int position) {
if ((position % 5) == 0) {
return TYPE_AD;
}
return TYPE_POST;
}
and I have this onBindViewHolder if i change this final dbFeed dbfeed = LemesosAdapter.get(position);
to final dbFeed dbfeed = LemesosAdapter.get(position+1);
the very 1st post wont be skipped . but the second time an advert is added it will be skipped.
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
if (getItemViewType(position) == TYPE_POST) {
// - get element from dataset at this position
// - replace the contents of the view with that element
PostViewHolder postViewHolder = (PostViewHolder)holder;
final dbFeed dbfeed = LemesosAdapter.get(position);
//Animation by yoyo library
YoYo.with(Techniques.BounceIn).playOn(postViewHolder.cardView);
String description;
description = Html.fromHtml(dbfeed.getDescription()).toString().replaceAll("n", "").trim().substring(0, 100).replace((char) 65532, (char) 32).trim() + "...";
postViewHolder.Title.setText(dbfeed.getTitle());
postViewHolder.Description.setText(description);
postViewHolder.Date.setText(dbfeed.getPubDate());
Picasso.with(context).load(dbfeed.getThumbnailUrl()).placeholder(R.drawable.ic_image).into(postViewHolder.Thumbnail);
postViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, NewsDetails.class);
intent.putExtra("ThumbNail", dbfeed.getThumbnailUrl());
intent.putExtra("Link", dbfeed.getThumbnailUrl());
intent.putExtra("Title", dbfeed.getTitle());
intent.putExtra("Description", dbfeed.getDescription());
intent.putExtra("Date", dbfeed.getPubDate());
context.startActivity(intent);
}
});
} else if (getItemViewType(position) == TYPE_AD ) {
}
}
and finally my getItemCount . in here I think is where the solution is. ive seen in this side in other post that I should do the same Modal as I did with my starting one ((itemcount %5) + itemcount) but it does not work
@Override
public int getItemCount() {
return ((LemesosAdapter.size()%5))+LemesosAdapter.size() ;
}
}
what I am missing here?
android android-recyclerview
android android-recyclerview
edited Nov 23 '18 at 10:57
Aniruddh Parihar
2,18911027
2,18911027
asked Nov 23 '18 at 10:42
DemeteorDemeteor
4491516
4491516
1
Can you please set item count like below.@Override public int getItemCount() { return (((int) LemesosAdapter.size()/5))+LemesosAdapter.size() ; }
– Mahavir Jain
Nov 23 '18 at 10:59
OMG, I'm not see that %. I see it as /.
– Hello World
Nov 23 '18 at 11:03
@MahavirJain this still skips each 5th position as well
– Demeteor
Nov 23 '18 at 11:05
Also you have to change logic.LemesosAdapter.get(getPosition(position)) fun getPosition(position: Int): Int = (position + (position / 5))
– Mahavir Jain
Nov 23 '18 at 11:41
@MahavirJain what is fun stands for? is it kotlin ?
– Demeteor
Nov 26 '18 at 12:44
|
show 2 more comments
1
Can you please set item count like below.@Override public int getItemCount() { return (((int) LemesosAdapter.size()/5))+LemesosAdapter.size() ; }
– Mahavir Jain
Nov 23 '18 at 10:59
OMG, I'm not see that %. I see it as /.
– Hello World
Nov 23 '18 at 11:03
@MahavirJain this still skips each 5th position as well
– Demeteor
Nov 23 '18 at 11:05
Also you have to change logic.LemesosAdapter.get(getPosition(position)) fun getPosition(position: Int): Int = (position + (position / 5))
– Mahavir Jain
Nov 23 '18 at 11:41
@MahavirJain what is fun stands for? is it kotlin ?
– Demeteor
Nov 26 '18 at 12:44
1
1
Can you please set item count like below.
@Override public int getItemCount() { return (((int) LemesosAdapter.size()/5))+LemesosAdapter.size() ; }
– Mahavir Jain
Nov 23 '18 at 10:59
Can you please set item count like below.
@Override public int getItemCount() { return (((int) LemesosAdapter.size()/5))+LemesosAdapter.size() ; }
– Mahavir Jain
Nov 23 '18 at 10:59
OMG, I'm not see that %. I see it as /.
– Hello World
Nov 23 '18 at 11:03
OMG, I'm not see that %. I see it as /.
– Hello World
Nov 23 '18 at 11:03
@MahavirJain this still skips each 5th position as well
– Demeteor
Nov 23 '18 at 11:05
@MahavirJain this still skips each 5th position as well
– Demeteor
Nov 23 '18 at 11:05
Also you have to change logic.
LemesosAdapter.get(getPosition(position)) fun getPosition(position: Int): Int = (position + (position / 5))
– Mahavir Jain
Nov 23 '18 at 11:41
Also you have to change logic.
LemesosAdapter.get(getPosition(position)) fun getPosition(position: Int): Int = (position + (position / 5))
– Mahavir Jain
Nov 23 '18 at 11:41
@MahavirJain what is fun stands for? is it kotlin ?
– Demeteor
Nov 26 '18 at 12:44
@MahavirJain what is fun stands for? is it kotlin ?
– Demeteor
Nov 26 '18 at 12:44
|
show 2 more comments
1 Answer
1
active
oldest
votes
As I see, every time ads show up it will skip one of your item because both post and ads share the same position. You can check by Log outside of these if-else condition.
if (getItemViewType(position) == TYPE_POST) {
// - get element from dataset at this position
// - replace the contents of the view with that element
PostViewHolder postViewHolder = (PostViewHolder)holder;
final dbFeed dbfeed = LemesosAdapter.get(position - count);
//Animation by yoyo library
YoYo.with(Techniques.BounceIn).playOn(postViewHolder.cardView);
String description;
description = Html.fromHtml(dbfeed.getDescription()).toString().replaceAll("n", "").trim().substring(0, 100).replace((char) 65532, (char) 32).trim() + "...";
postViewHolder.Title.setText(dbfeed.getTitle());
postViewHolder.Description.setText(description);
postViewHolder.Date.setText(dbfeed.getPubDate());
Picasso.with(context).load(dbfeed.getThumbnailUrl()).placeholder(R.drawable.ic_image).into(postViewHolder.Thumbnail);
postViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, NewsDetails.class);
intent.putExtra("ThumbNail", dbfeed.getThumbnailUrl());
intent.putExtra("Link", dbfeed.getThumbnailUrl());
intent.putExtra("Title", dbfeed.getTitle());
intent.putExtra("Description", dbfeed.getDescription());
intent.putExtra("Date", dbfeed.getPubDate());
context.startActivity(intent);
}
});
} else if (getItemViewType(position) == TYPE_AD ) {
count += 1
}
Yeah I understand why is happening, but I dont know how I can solve this without breaking the entire thing
– Demeteor
Nov 23 '18 at 10:53
If you have 2 set of data, I think you need some variable to count every time ads show up. Then use that count to decrease position in item of Type_post.
– Hello World
Nov 23 '18 at 10:57
Yes as I am trying to do. here (LemesosAdapter.size()%5))+LemesosAdapter.size() this will add back to the count as far as ive seen in other post. the problem is that I cant figure out how to actually make it work. thanks for trying though
– Demeteor
Nov 23 '18 at 10:59
Please try my new code.
– Hello World
Nov 23 '18 at 11:02
what was changed here? count +=1 ? basically you want me to add an element back each time I use type_ad?
– Demeteor
Nov 23 '18 at 11:07
|
show 2 more comments
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
});
}
});
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%2f53445141%2fmultiple-viewholder-in-recyclerview-skips-items%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As I see, every time ads show up it will skip one of your item because both post and ads share the same position. You can check by Log outside of these if-else condition.
if (getItemViewType(position) == TYPE_POST) {
// - get element from dataset at this position
// - replace the contents of the view with that element
PostViewHolder postViewHolder = (PostViewHolder)holder;
final dbFeed dbfeed = LemesosAdapter.get(position - count);
//Animation by yoyo library
YoYo.with(Techniques.BounceIn).playOn(postViewHolder.cardView);
String description;
description = Html.fromHtml(dbfeed.getDescription()).toString().replaceAll("n", "").trim().substring(0, 100).replace((char) 65532, (char) 32).trim() + "...";
postViewHolder.Title.setText(dbfeed.getTitle());
postViewHolder.Description.setText(description);
postViewHolder.Date.setText(dbfeed.getPubDate());
Picasso.with(context).load(dbfeed.getThumbnailUrl()).placeholder(R.drawable.ic_image).into(postViewHolder.Thumbnail);
postViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, NewsDetails.class);
intent.putExtra("ThumbNail", dbfeed.getThumbnailUrl());
intent.putExtra("Link", dbfeed.getThumbnailUrl());
intent.putExtra("Title", dbfeed.getTitle());
intent.putExtra("Description", dbfeed.getDescription());
intent.putExtra("Date", dbfeed.getPubDate());
context.startActivity(intent);
}
});
} else if (getItemViewType(position) == TYPE_AD ) {
count += 1
}
Yeah I understand why is happening, but I dont know how I can solve this without breaking the entire thing
– Demeteor
Nov 23 '18 at 10:53
If you have 2 set of data, I think you need some variable to count every time ads show up. Then use that count to decrease position in item of Type_post.
– Hello World
Nov 23 '18 at 10:57
Yes as I am trying to do. here (LemesosAdapter.size()%5))+LemesosAdapter.size() this will add back to the count as far as ive seen in other post. the problem is that I cant figure out how to actually make it work. thanks for trying though
– Demeteor
Nov 23 '18 at 10:59
Please try my new code.
– Hello World
Nov 23 '18 at 11:02
what was changed here? count +=1 ? basically you want me to add an element back each time I use type_ad?
– Demeteor
Nov 23 '18 at 11:07
|
show 2 more comments
As I see, every time ads show up it will skip one of your item because both post and ads share the same position. You can check by Log outside of these if-else condition.
if (getItemViewType(position) == TYPE_POST) {
// - get element from dataset at this position
// - replace the contents of the view with that element
PostViewHolder postViewHolder = (PostViewHolder)holder;
final dbFeed dbfeed = LemesosAdapter.get(position - count);
//Animation by yoyo library
YoYo.with(Techniques.BounceIn).playOn(postViewHolder.cardView);
String description;
description = Html.fromHtml(dbfeed.getDescription()).toString().replaceAll("n", "").trim().substring(0, 100).replace((char) 65532, (char) 32).trim() + "...";
postViewHolder.Title.setText(dbfeed.getTitle());
postViewHolder.Description.setText(description);
postViewHolder.Date.setText(dbfeed.getPubDate());
Picasso.with(context).load(dbfeed.getThumbnailUrl()).placeholder(R.drawable.ic_image).into(postViewHolder.Thumbnail);
postViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, NewsDetails.class);
intent.putExtra("ThumbNail", dbfeed.getThumbnailUrl());
intent.putExtra("Link", dbfeed.getThumbnailUrl());
intent.putExtra("Title", dbfeed.getTitle());
intent.putExtra("Description", dbfeed.getDescription());
intent.putExtra("Date", dbfeed.getPubDate());
context.startActivity(intent);
}
});
} else if (getItemViewType(position) == TYPE_AD ) {
count += 1
}
Yeah I understand why is happening, but I dont know how I can solve this without breaking the entire thing
– Demeteor
Nov 23 '18 at 10:53
If you have 2 set of data, I think you need some variable to count every time ads show up. Then use that count to decrease position in item of Type_post.
– Hello World
Nov 23 '18 at 10:57
Yes as I am trying to do. here (LemesosAdapter.size()%5))+LemesosAdapter.size() this will add back to the count as far as ive seen in other post. the problem is that I cant figure out how to actually make it work. thanks for trying though
– Demeteor
Nov 23 '18 at 10:59
Please try my new code.
– Hello World
Nov 23 '18 at 11:02
what was changed here? count +=1 ? basically you want me to add an element back each time I use type_ad?
– Demeteor
Nov 23 '18 at 11:07
|
show 2 more comments
As I see, every time ads show up it will skip one of your item because both post and ads share the same position. You can check by Log outside of these if-else condition.
if (getItemViewType(position) == TYPE_POST) {
// - get element from dataset at this position
// - replace the contents of the view with that element
PostViewHolder postViewHolder = (PostViewHolder)holder;
final dbFeed dbfeed = LemesosAdapter.get(position - count);
//Animation by yoyo library
YoYo.with(Techniques.BounceIn).playOn(postViewHolder.cardView);
String description;
description = Html.fromHtml(dbfeed.getDescription()).toString().replaceAll("n", "").trim().substring(0, 100).replace((char) 65532, (char) 32).trim() + "...";
postViewHolder.Title.setText(dbfeed.getTitle());
postViewHolder.Description.setText(description);
postViewHolder.Date.setText(dbfeed.getPubDate());
Picasso.with(context).load(dbfeed.getThumbnailUrl()).placeholder(R.drawable.ic_image).into(postViewHolder.Thumbnail);
postViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, NewsDetails.class);
intent.putExtra("ThumbNail", dbfeed.getThumbnailUrl());
intent.putExtra("Link", dbfeed.getThumbnailUrl());
intent.putExtra("Title", dbfeed.getTitle());
intent.putExtra("Description", dbfeed.getDescription());
intent.putExtra("Date", dbfeed.getPubDate());
context.startActivity(intent);
}
});
} else if (getItemViewType(position) == TYPE_AD ) {
count += 1
}
As I see, every time ads show up it will skip one of your item because both post and ads share the same position. You can check by Log outside of these if-else condition.
if (getItemViewType(position) == TYPE_POST) {
// - get element from dataset at this position
// - replace the contents of the view with that element
PostViewHolder postViewHolder = (PostViewHolder)holder;
final dbFeed dbfeed = LemesosAdapter.get(position - count);
//Animation by yoyo library
YoYo.with(Techniques.BounceIn).playOn(postViewHolder.cardView);
String description;
description = Html.fromHtml(dbfeed.getDescription()).toString().replaceAll("n", "").trim().substring(0, 100).replace((char) 65532, (char) 32).trim() + "...";
postViewHolder.Title.setText(dbfeed.getTitle());
postViewHolder.Description.setText(description);
postViewHolder.Date.setText(dbfeed.getPubDate());
Picasso.with(context).load(dbfeed.getThumbnailUrl()).placeholder(R.drawable.ic_image).into(postViewHolder.Thumbnail);
postViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, NewsDetails.class);
intent.putExtra("ThumbNail", dbfeed.getThumbnailUrl());
intent.putExtra("Link", dbfeed.getThumbnailUrl());
intent.putExtra("Title", dbfeed.getTitle());
intent.putExtra("Description", dbfeed.getDescription());
intent.putExtra("Date", dbfeed.getPubDate());
context.startActivity(intent);
}
});
} else if (getItemViewType(position) == TYPE_AD ) {
count += 1
}
edited Nov 23 '18 at 11:01
answered Nov 23 '18 at 10:51
Hello WorldHello World
17011
17011
Yeah I understand why is happening, but I dont know how I can solve this without breaking the entire thing
– Demeteor
Nov 23 '18 at 10:53
If you have 2 set of data, I think you need some variable to count every time ads show up. Then use that count to decrease position in item of Type_post.
– Hello World
Nov 23 '18 at 10:57
Yes as I am trying to do. here (LemesosAdapter.size()%5))+LemesosAdapter.size() this will add back to the count as far as ive seen in other post. the problem is that I cant figure out how to actually make it work. thanks for trying though
– Demeteor
Nov 23 '18 at 10:59
Please try my new code.
– Hello World
Nov 23 '18 at 11:02
what was changed here? count +=1 ? basically you want me to add an element back each time I use type_ad?
– Demeteor
Nov 23 '18 at 11:07
|
show 2 more comments
Yeah I understand why is happening, but I dont know how I can solve this without breaking the entire thing
– Demeteor
Nov 23 '18 at 10:53
If you have 2 set of data, I think you need some variable to count every time ads show up. Then use that count to decrease position in item of Type_post.
– Hello World
Nov 23 '18 at 10:57
Yes as I am trying to do. here (LemesosAdapter.size()%5))+LemesosAdapter.size() this will add back to the count as far as ive seen in other post. the problem is that I cant figure out how to actually make it work. thanks for trying though
– Demeteor
Nov 23 '18 at 10:59
Please try my new code.
– Hello World
Nov 23 '18 at 11:02
what was changed here? count +=1 ? basically you want me to add an element back each time I use type_ad?
– Demeteor
Nov 23 '18 at 11:07
Yeah I understand why is happening, but I dont know how I can solve this without breaking the entire thing
– Demeteor
Nov 23 '18 at 10:53
Yeah I understand why is happening, but I dont know how I can solve this without breaking the entire thing
– Demeteor
Nov 23 '18 at 10:53
If you have 2 set of data, I think you need some variable to count every time ads show up. Then use that count to decrease position in item of Type_post.
– Hello World
Nov 23 '18 at 10:57
If you have 2 set of data, I think you need some variable to count every time ads show up. Then use that count to decrease position in item of Type_post.
– Hello World
Nov 23 '18 at 10:57
Yes as I am trying to do. here (LemesosAdapter.size()%5))+LemesosAdapter.size() this will add back to the count as far as ive seen in other post. the problem is that I cant figure out how to actually make it work. thanks for trying though
– Demeteor
Nov 23 '18 at 10:59
Yes as I am trying to do. here (LemesosAdapter.size()%5))+LemesosAdapter.size() this will add back to the count as far as ive seen in other post. the problem is that I cant figure out how to actually make it work. thanks for trying though
– Demeteor
Nov 23 '18 at 10:59
Please try my new code.
– Hello World
Nov 23 '18 at 11:02
Please try my new code.
– Hello World
Nov 23 '18 at 11:02
what was changed here? count +=1 ? basically you want me to add an element back each time I use type_ad?
– Demeteor
Nov 23 '18 at 11:07
what was changed here? count +=1 ? basically you want me to add an element back each time I use type_ad?
– Demeteor
Nov 23 '18 at 11:07
|
show 2 more comments
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.
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%2f53445141%2fmultiple-viewholder-in-recyclerview-skips-items%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
1
Can you please set item count like below.
@Override public int getItemCount() { return (((int) LemesosAdapter.size()/5))+LemesosAdapter.size() ; }
– Mahavir Jain
Nov 23 '18 at 10:59
OMG, I'm not see that %. I see it as /.
– Hello World
Nov 23 '18 at 11:03
@MahavirJain this still skips each 5th position as well
– Demeteor
Nov 23 '18 at 11:05
Also you have to change logic.
LemesosAdapter.get(getPosition(position)) fun getPosition(position: Int): Int = (position + (position / 5))
– Mahavir Jain
Nov 23 '18 at 11:41
@MahavirJain what is fun stands for? is it kotlin ?
– Demeteor
Nov 26 '18 at 12:44