BackgroundColorSpan
is not working in recyclerView
. It is working properly with the listView
but not with recyclerView
. Any idea why? or How can i overcome through this problem.
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.no.setText(String.valueOf(position + 1));
ExerciseRoutineService exerciseRoutineService =
exerciselist.get(position);
String exerciseText = "i exercise by " +
exerciseRoutineService.getExerciseType()
+ " for about " +
exerciseRoutineService.getFrequency() +
" " +
exerciseRoutineService.getDuration() + "
minutes";
holder.exercise.setText(exerciseText);
int start;
start=exerciseText.indexOf
(exerciseRoutineService.getExerciseType());
int end = start +
exerciseRoutineService.getExerciseType().length();
StringBuilder captionBuilder = new StringBuilder();
captionBuilder.append(exerciseText);
SpannableStringBuilder commentBuilder = new
SpannableStringBuilder(captionBuilder);
commentBuilder.setSpan(new BackgroundColorSpan(Color.GREEN),
start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.exercise.setText(commentBuilder);
}