-1
我想通過使用Achartengine顯示扇形圖在的GridView,的Android GridView控件與扇形圖,UnsupportedOperationException異常:addView(查看,的LayoutParams)
它說java.lang.UnsupportedOperationException:addView(查看,的LayoutParams)在適配器視圖不支持 我不知道爲什麼,有些建議PLZ ....
我的適配器類別:
public class GraphAdapter extends BaseAdapter {
class ViewHolder {
private LinearLayout layout;
private int[] COLORS = new int[] { Color.GREEN, Color.BLUE,
Color.MAGENTA, Color.CYAN };
private CategorySeries mSeries;
private DefaultRenderer mRenderer;
private GraphicalView mChartView;
public ViewHolder(View view) {
layout = (LinearLayout) view.findViewById(R.id.adapter_dash_graph);
mRenderer = new DefaultRenderer();
mSeries = new CategorySeries("");
mChartView = ChartFactory.getPieChartView(mContext, mSeries,
mRenderer);
}
private void updateChild(String[] names, int[] values) {
renderGraph(names, values);
// Draw chart
mChartView.repaint();
layout.addView(mChartView);
}
private void renderGraph(String[] names, int[] values) {
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(mContext.getResources().getColor(
android.R.color.white));
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(20);
mRenderer.setLabelsColor(mContext.getResources().getColor(
R.color.blue_dark));
mRenderer.setLegendTextSize(20);
mRenderer.setShowLegend(true);
mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
mRenderer.setZoomButtonsVisible(false);
mRenderer.setStartAngle(90);
mRenderer.setZoomEnabled(false);
mRenderer.setPanEnabled(false);
for (int i = 0; i < values.length; i++) {
mSeries.add(names[i] + " " + values[i], values[i]);
SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
renderer.setColor(COLORS[(mSeries.getItemCount() - 1)
% COLORS.length]);
mRenderer.addSeriesRenderer(renderer);
}
}
}
private Context mContext;
private List<OverallDetails> mUserMenus;
public GraphAdapter(Context context, List<OverallDetails> slideMenus) {
this.mContext = context;
this.mUserMenus = slideMenus;
}
@Override
public int getCount() {
return mUserMenus.size();
}
@Override
public OverallDetails getItem(int position) {
return mUserMenus.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup group) {
ViewHolder viewHolder = null;
if (convertView == null) {
convertView = View.inflate(mContext, R.layout.adapter_graph, group);
viewHolder = new ViewHolder(convertView);
convertView.setTag(viewHolder);
}
viewHolder.updateChild(
mContext.getResources().getStringArray(R.array.graph_name),
mContext.getResources().getIntArray(R.array.graph_values));
return convertView;
}
}