在得到结果后,Android饼图中没有显示

时间:2015-02-27 10:58:47

标签: android

在我的android项目中,我使用achartengine.jar查看饼图..

代码是: -

public class AndroidPopupWindowActivity111_new_made2 extends Activity {

    private static int[] COLORS = new int[] { Color.MAGENTA, Color.CYAN };  
    LinearLayout layout;
    private CategorySeries mSeries = new CategorySeries("");  
    private DefaultRenderer mRenderer = new DefaultRenderer();  
    private GraphicalView mChartView;  
    EditText name1,name2;


    private  int[] VALUES = { 40 , 60 };
     String x1,y1;

     String[] NAME_LIST ; 

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.popup_main);

        mRenderer.setApplyBackgroundColor(true);
        mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));  
        mRenderer.setChartTitleTextSize(20);  
        mRenderer.setLabelsTextSize(15);  
        mRenderer.setLegendTextSize(15);  
        mRenderer.setMargins(new int[] { 20, 30, 15, 0 });  
        mRenderer.setZoomButtonsVisible(true);  
        mRenderer.setStartAngle(90);

        final Button btnOpenPopup = (Button)findViewById(R.id.openpopup);

        mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer); 


        btnOpenPopup.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
   LayoutInflater layoutInflater    = (LayoutInflater)getBaseContext()  .getSystemService(LAYOUT_INFLATER_SERVICE);  


       View popupView = layoutInflater.inflate(R.layout.main_piechart, null);  
             final PopupWindow popupWindow = new PopupWindow( popupView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);  
             layout = (LinearLayout)popupView.findViewById(R.id.chart); 
             layout.addView(mChartView);


                 if (mChartView != null) {  

                    mChartView.repaint();  

                 }  


             Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
             btnDismiss.setOnClickListener(new Button.OnClickListener(){

     @Override
     public void onClick(View v) {

      popupWindow.dismiss();
     }});

             popupWindow.showAsDropDown(btnOpenPopup, 50, -30);

   }});
    }

}

这里我有2个编辑文字字段。填写编辑文本字段后,当我点击提交按钮时,它会在饼图中显示饼图...也是一个关闭的按钮..在点击关闭按钮后我将转到上一个活动,当我再次填写编辑文本字段并单击程序停止的提交按钮时..它显示错误:--- < / p>

    FATAL EXCEPTION: main
     Process: in.wptrafficanalyzer.achartenginepiechart,  java.lang.IllegalStateException: The specified child already has a parent. 
You must call removeView() on the child's parent first.
        at android.view.ViewGroup.addViewInner(ViewGroup.java:3718)
        at android.view.ViewGroup.addView(ViewGroup.java:3564)
        at android.view.ViewGroup.addView(ViewGroup.java:3509)
        at android.view.ViewGroup.addView(ViewGroup.java:3485)

我的代码中的问题在哪里?

2 个答案:

答案 0 :(得分:0)

添加此代码

 mChartView = ChartFactory.getPieChartView(arg0.getContext(), mSeries,
                    mRenderer);

之前

layout.addView(mChartView);

答案 1 :(得分:0)

我明白了。程序逻辑存在问题......感谢帮助