I need to change the color for selected listview item for different color. I had to implemented for the below code for changing list item color, but if I select the 1st item of the visible Item after scrolling it had to change the color every newly visibled item. Anyone can suggest me for the best solution.
Code snippet.
@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int i) {
PlayListItem nature = mItems.get(i);
try {
if (nature.getmInnerTitle() != null && nature.getmInnerTVName() != null) {
viewHolder.tvInnerTitle.setText(nature.getmInnerTitle());
mVideoID = nature.getmInnerVideoID();
Picasso.with(activity)
.load(nature.getmInnerThumpnailURL())
/* .placeholder(R.drawable.my_thumnail_small)*/
.into(viewHolder.imgInnerThumbnail);
viewHolder.tvInnerTVName.setText("by " + nature.getmInnerTVName());
}
} catch (NullPointerException e) {
e.printStackTrace();
}
viewHolder.item_view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("Save Value------Inner-------->" + save);
Toast.makeText(activity, "Position---->" + i + " Playlist ID : ", Toast.LENGTH_LONG).show();
// Change BG color for selected List Item
VideoPlayActivity.mRecyclerView.getChildAt(i).setBackgroundColor(
Color.parseColor("#EEEEEE"));
System.out.println("Save Value------1-------->" + save);
if (save != -1 && save != i) {
VideoPlayActivity.mRecyclerView.getChildAt(save).setBackgroundColor(
Color.parseColor("#FFFFFF"));
System.out.println("Save Value------2-------->" + save);
}
save = i;
System.out.println("Save Value------3-------->" + save);
}
});
viewHolder.itemView.post(new Runnable() {
@Override
public void run() {
int cellWidth = viewHolder.itemView.getWidth();// this will give you cell width dynamically
int cellHeight = viewHolder.itemView.getHeight();// this will give you cell height dynamically
mdynamicHeight.HeightChange(i, cellHeight); //call your iterface hear
}
});
}