2012-07-28 26 views
-1

我有database.1st表2個表是「INC」和第2表「REC」。在第一個表,我有以下字段:比較使用的數據從數據庫

id item price qty total cat group recc reccid 
1 sddf 65  1 65 rer dfd true 1 

In 2nd table: 

id date  increment type 
1 27/07/2012 6   daily. 

所以我想是我從table1檢索數據(在這沒有問題),並顯示使用simplecursoradapter在列表視圖中。在這個列表視圖中,我有5個textviews顯示數據。在那第五個textview應該是動態的(即),如果表中的「recc」是真的意味着我從第二張表中檢索數據,並根據增量進行一些計算。但是當我從table2中檢索數據時,它總是單獨獲取第一個條目數據。基於table1的行長度應該得到table2的增量值。請幫助我..提前致謝。

我的代碼如下:

Cursor c = db.getExpensetitle(intent.getStringExtra("grpsdbexp"));-------->This is from table1. 
      startManagingCursor(c);  

      from = new String[] {db.KEY_DATE,db.KEY_DESC,db.KEY_INCOME,db.KEY_QUANTITY,db.KEY_ROWID}; 
      to = new int[] {R.id.text1 ,R.id.text3,R.id.text5,R.id.text7,R.id.text11}; 

        SimpleCursorAdapter notes = 
          new SimpleCursorAdapter(this, R.layout.columnviewexp, c, from, to) 
{ 
    @Override 
    public void bindView(View view, Context context, Cursor cursor) 
    { 
     String reurrence= cursor.getString(cursor.getColumnIndex("recurrence")); 
     float total=Float.valueOf(cursor.getString(cursor.getColumnIndex("total"))); 
     TextView text1=(TextView)view.findViewById(R.id.text1); 
     TextView text3=(TextView)view.findViewById(R.id.text3); 
     TextView text5=(TextView)view.findViewById(R.id.text5); 
     TextView text7=(TextView)view.findViewById(R.id.text7); 
     TextView text9=(TextView)view.findViewById(R.id.text9); 
     TextView text11=(TextView)view.findViewById(R.id.text11); 

     TextView recccind=(TextView)findViewById(R.id.reccurind);  
     String text=null;  
     String recctotal=null; 

     if(reurrence.equals("true")) 
     {  
      Cursor c1=db.recctable(); 
      startManagingCursor(c1); ---------->This is from table 2. 
      System.out.println("No="+c1.getString(c1.getColumnIndex("startdate"))); 
      String dates=(c1.getString(c1.getColumnIndex("startdate"))); 
      String types=(c1.getString(c1.getColumnIndex("recurrencetype"))); 
      int recc=Integer.parseInt((c1.getString(c1.getColumnIndex("increment")))); 
       c1.moveToNext();  
      SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); 
      String currentDateandTime = sdf.format(new Date()); 
      Calendar cal=Calendar.getInstance(); 

      Date dt=null; 
      try 
      { 
       dt = sdf.parse(dates); 
       cal.setTime(dt); 
      } catch (ParseException e) 
      { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      }    

      int daysInSameMonth=0; ------------------>For getting this value only i am doing this..It gives always the first entry count. 
      int count[]=new int[c1.getCount()]; 
      for(int j=1;j<recc;j++) 
      { 
       int currentDay= cal.get(Calendar.DAY_OF_MONTH); 
       int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);  
       System.out.println("b4 inc"); 
       daysInSameMonth++; 
       if(types.equals("Daily")) 
       {        
        cal.add(Calendar.DAY_OF_MONTH, 1);  
        Date dtNew=cal.getTime(); 
        cal.setTime(dtNew);       
        if(currentDay==lastDay) 
        { 
         System.out.println("count="+daysInSameMonth); 

         break; 
        } 
//     System.out.println("days="+daysInSameMonth[i]); 

       } 
       else if(types.equals("Weekly")) 
       { 
        System.out.println("Inside week"); 
        System.out.println("current="+currentDay); 
        System.out.println("last="+lastDay); 
        cal.add(Calendar.DAY_OF_MONTH, 7); 
        if(currentDay<=lastDay) 
        {    
         break; 
        } 
       }   

      }  
      System.out.println("subbu="+daysInSameMonth); 
      System.out.println("totttt="+daysInSameMonth*total); 

      recctotal=String.valueOf(daysInSameMonth*total); 
      text9.setText(recctotal); 

     } 

     else 
     {  

      text9.setText(cursor.getString(cursor.getColumnIndex(db.KEY_TOTAL)));  
     }  
+0

爲startManagingCursor方法添加代碼或類 – Khan 2012-07-28 05:28:26

+0

謝謝汗..請給更多的細節.. – 2012-07-28 05:30:34

回答

0

你應該爲使用循環或而正從表中多行數據如下圖所示

if(cursor!=null && cursor.getCount()!=0){ 

    for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){ 

// Do here your stuff what you want 

    } 
} 
+0

謝謝汗..但它不會滿足我的要求..通過您的代碼它會給最後的值 – 2012-07-28 05:41:16

+0

汗ru? – 2012-07-28 05:44:13

+0

來http://chat.stackoverflow.com/rooms/11936/android-lite討論 – Khan 2012-07-28 05:48:54