1
我想使用ListView在ListView的每一行中顯示餅圖。如何編寫用於在Android中顯示多個餅圖的ListView適配器
這是我的餅圖類
public class PieChart extends View {
public PieChart(Context context) {
super(context);
}
public PieChart(Context context, AttributeSet attrs){
super(context, attrs);
}
public void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(Color.RED);
canvas.drawArc(new RectF(0, 0, 150, 150), 180, 90, true, paint);
paint.setColor(Color.BLUE);
canvas.drawArc(new RectF(0, 0, 150, 150), 90, 90, true, paint);
}
}
這是我爲ListView佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background"
android:orientation="vertical" >
<TextView
style="@style/title_bar"
android:text="@string/scenario_reports" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/list_view_item_bg"
android:cacheColorHint="#00000000"
android:divider="@color/list_view_divider"
android:dividerHeight="2dip" >
</ListView>
</LinearLayout>
這是我的ListView的行佈局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<view
android:id="@+id/pie_chart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
class="com.bob.hellotest.GameView" />
<TextView
android:id="@+id/scenario_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/pie_chart"
android:padding="10dp"
android:textSize="16sp" />
</RelativeLayout>
這是活動的onCreate方法
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scenario_report);
}
我的問題是適配器
public View getView(int position, View row, ViewGroup parent) {
LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = li.inflate(R.layout.list_view_scenario_pie, parent, false);
View pie = (View) rowView.findViewById(R.id.pie_chart);
TextView name = (TextView) rowView.findViewById(R.id.scenario_name);
????????????????
return rowView;
}
我被困在適配器,我不知道如何把它收回去適配器。 任何人都可以幫忙。乾杯!!