2012-02-02 24 views
0
public Cursor ShowBarchartIncome(int yearChoose) { 
    Cursor cur1=db.rawQuery("SELECT "+COLEXPENSE+" as _id,"+" SUM(PRICE) as price from "+EXPENSETABLE 
    +" WHERE ("+YEAREX+" = "+2012+") AND ("+MONTHEX+" = 01) AND ("+TYPE+" = 'income')",new String [] {}); 
    return cur1;  
    } 
public class BarGraph { 
    public Intent getIntent(Context context) { 

     DBHelper.open();    
     int spn=editYEAR.getId(); 
     int e = Integer.valueOf(spn); 
     c = DBHelper.ShowBarchartIncome(e); 
     startManagingCursor(c); 

     //data 1 
     int[] y ={**c.getCount()**,443,443,456,234,123,342,134,123,645,234,274}; 
     CategorySeries series = new CategorySeries("รายรับ"); 
     for(int i=0;i<y.length;i++){ 
     series.add("Bar "+ (i+1),y[i]);  
    } 
} 

我無法得到真實的數據和價格將其返回1 int[] y ={c.getCount()}我想從光標int數據請幫我

我怎樣才能獲得的數據和價格showbarchartincome如果真正的數據是15000

回答

2

嘗試insead的new String [] {}只使用null。

Cursor cur1=db.rawQuery("SELECT "+COLEXPENSE+" as _id,"+" SUM(PRICE) as price from "+EXPENSETABLE 
      +" WHERE ("+YEAREX+" = "+2012+") AND ("+MONTHEX+" = 01) AND ("+TYPE+" = 'income')", null); 

更新:

要想從光標數據,你應該加入下面幾行:

c.moveToFirst(); 
price = c.getInt(c.getColumnIndex("price")); 

c.getCount() just show the number of returned records. 
+0

也看到我的最新答案的版本。 – Yury 2012-02-02 11:29:33

+0

謝謝你Yury 我來自泰國 – barmboy 2012-02-02 12:26:13