2011-07-06 18 views
1

我正在使用achartengine繪製圖表,在將新值插入數據庫時​​將更新圖表。與數據庫整合時的achartengine問題

chart() 
{ 
if (mChartView == null) 
{   
    d = new BuildMultipleDataset();   
    db.open(); 

    //code for some database query    
    LinearLayout layout = (LinearLayout) findViewById(R.id.chart); 
    mChartView = ChartFactory.getLineChartView(this, d.datasetbuilder(cursor1,cursor2), d.render()); 
    layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, chartHeight));  

    db.close();  
} 
else 
{ 
    mChartView.repaint(); 
} 
} 

我從數據庫觸發更新時調用此方法。在那段時間,我讓mChartView = null;但問題是它沒有繪製更新的圖表。只有當我切換屏幕方向時,更新纔會反映到圖表中。我的代碼有什麼問題

回答

2

我只有在我刪除了View,設置了mChartView = null;,定義了mChartView,並且設置了View之後,才得以工作。

layout.removeView(mChartView); 
mChartView = null; 
mChartView = ChartFactory //rest of mChartView code 
layout.addView(mChartView);