我需要为不同颜色更改所选列表视图项的颜色。我必须为下面的代码实现更改列表项颜色,但如果我在滚动后选择可见项的第一项,则必须更改每个新显示项的颜色。任何人都可以建议我找到最佳解决方案。
代码段。
@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
}
});
}
答案 0 :(得分:1)
是的,最后我得到了答案。这是工作代码段。
Slider {
id: slider
anchors.centerIn: parent
updateValueWhileDragging:true
activeFocusOnPress:true
style: SliderStyle {
id:sliderStyle
//Slider handler
handle: Rectangle {
id:handler
width: 22
height: 44
radius:2
antialiasing: true
Image{
source:"icons/slidercenter.png"
anchors.centerIn: parent
}
}
//Slider Groove
groove: Item {
id:slidergroove
implicitHeight: 50
implicitWidth: temperaturePage.width -50
}
}
}