1
我有列表項中的Canvas視圖的RecycleViewer。我如何在我的RecycleViewerAdapter中更改Canvas視圖的backgrouncolor?如何在RecycleViewer上更改Canvas?
下面是我onBindViewHolder方法在我RecycleViewerAdapter
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.openprice.setText(mopenPrice.get(position));
//How can I change backgrouncolor canvas view ????
}
我ViewHolder
public ViewHolder(View itemView) {
super(itemView);
openprice = (TextView) itemView.findViewById(R.id.openprice);
viewx = (View) itemView.findViewById(R.id.viewx);
}
itemlist.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:background="@drawable/border_listfavorite"
>
<view class="com.eusecom.exforu.MyView"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:id="@+id/viewx"/>
<TextView
android:id="@+id/opentxt"
android:text="@string/opentxt"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/viewx"
/>
<TextView
android:id="@+id/openprice"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/opentxt"
android:layout_below="@+id/viewx"
/>
</RelativeLayout>
MyView.java
public class MyView extends View {
public MyView(Context cxt, AttributeSet attrs) {
super(cxt, attrs);
setMinimumHeight(100);
setMinimumWidth(100);
}
@Override
protected void onDraw(Canvas cv) {
cv.drawColor(Color.WHITE);
Paint p = new Paint();
p.setColor(Color.GREEN);
p.setStrokeWidth(5);
cv.drawLine(20, 0, 20, cv.getHeight(), p);
}
}
它看起來不錯,但我需要改變viewx的顏色,這是查看如何在我的itemlist.xml和ViewHolder看到。我如何在ViewHolder中保存這個viewx? setCustomColor(int)的類型是未定義的類型查看 – eurosecom
無論如何,「viewx」是instanceof MyView,所以你可以形式化它並使用?看到更新的答案。 – sowmia
謝謝你一切都好。 – eurosecom