我正在尝试使用数据库中的一些数据,但函数只使用第一次输入的数据。我应该添加什么来浏览数据库中的所有条目?
public void drawdayplan(){
DatabaseConnector dbConnector = new DatabaseConnector(Clock.this);
Intent a = getIntent();
String d_m_y = a.getStringExtra("d_m_y");
dbConnector.open();
Cursor result = dbConnector.gethour(d_m_y);
if(result.moveToFirst()){
int hourfromIndex = result.getColumnIndex("inthourfrom");
int hourtoIndex = result.getColumnIndex("inthourto");
int colourIndex = result.getColumnIndex("colour");
hourfrom = result.getInt(hourfromIndex);
hourto = result.getInt(hourtoIndex);
colour = result.getString(colourIndex);
// here are some steps with painting which are using this variables
}
}
result.close();
dbConnector.close();
}
答案 0 :(得分:1)
但是函数只使用第一次输入的数据。
你永远不会要求超过第一行。在这样的循环中调用moveToNext()
:
while(result.moveToNext()){
// Read each row
}