-1

我在数据库中有 2 个表。第一个表是“inc”,第二个表是“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个文本视图来显示数据。如果第5个文本视图应该是动态的(即)表 1 中的“recc”为真表示我正在从第二个表中检索数据,并且基于增量我正在做一些计算。但是当我从表 2 中检索数据时,它总是单独获取第一个条目数据。基于表 1它应该从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)));       
      }      
4

1 回答 1

0

您应该使用for循环或 while 从表中获取多行数据,如下所示

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

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

 // Do here your stuff what you want 

  }
 }
于 2012-07-28T05:32:11.430 回答