我在database.1st表中有两个表是“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中检索数据(没有问题)并在listview中使用simplecursoradapter显示。在这个列表视图中我有5个textviews来显示数据。在第5个textview应该是动态的( ie)如果table1中的“recc”为真意味着我正在从第二个表中检索数据并根据我正在进行一些计算的增量。但是当我从table2中检索数据时,它总是单独获取第一个条目数据。基于table1表示行的长度,应该从表格中获取该增量值。请帮助我......提前谢谢。
我的代码如下:
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 :(得分:0)
您必须使用进行循环,或者同时从表中获取多行数据,如下所示
if(cursor!=null && cursor.getCount()!=0){
for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){
// Do here your stuff what you want
}
}