private static final String DATABASE_CREATE =
"create table tasks (_id integer primary key autoincrement, "
+ "title text not null,"
+"location text not null, "
+ "body text not null , "
+" goaldate text not null , "
+" absolutedate text not null , "
+"currentdate text not null , "
+"prio text not null, "
+"done text not null, "
+"category text not null, "
+"timespent text not null, "
+"pososto text not null,"
+"father text not null);";
// fetch all tasks(tasks and subtasks)
public Cursor fetchTasks() {
return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
KEY_BODY,KEY_location , KEY_GOAL_DATE,KEY_ABSOLUTE_DATE, KEY_DATE_CURRENT ,KEY_PRIO,KEY_DONE, KEY_CATEGORY,KEY_TIME_SPEND,KEY_POSOSTO, KEY_FATHER},null, null, null, null, null);
}
//fetch subtasks of a task, given the father's key
public Cursor fetchSubTasks(String id) {
return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
KEY_BODY,KEY_location , KEY_GOAL_DATE,KEY_ABSOLUTE_DATE, KEY_DATE_CURRENT ,KEY_PRIO,KEY_DONE, KEY_CATEGORY,KEY_TIME_SPEND,KEY_POSOSTO, KEY_FATHER}, KEY_FATHER + " LIKE" + "'"+ id+"'", null, null, null, null);
}
//fetch a subtask
public Cursor fetchSubTask(String fid,String uid) { // tropopoihsh ths methodou wste sthn arxiki othoni na fainontai mono oi tasks
return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
KEY_BODY,KEY_location , KEY_GOAL_DATE,KEY_ABSOLUTE_DATE, KEY_DATE_CURRENT ,KEY_PRIO,KEY_DONE, KEY_CATEGORY,KEY_TIME_SPEND,KEY_POSOSTO, KEY_FATHER}, KEY_FATHER + " LIKE" + " '"+ fid +" '"+ " AND " + KEY_ROWID + " LIKE " + " '"+ uid +"' ", null, null, null, null);
}
mCursor= mDbHelper.fetchTasks();//fetching all the tasks
int numberoftasks= mCursor.getCount();
this.mCursor.moveToFirst();
int n,m;
String id, idf;
int columnIndex= 0;
for(n=0;n<=numberoftasks;n++){
id=this.mCursor.getString(0);//unique id of the current task
mCursor=mDbHelper.fetchSubTasks(id);// fetching the subtasks with father_id=id
String[] my = new String[mCursor.getCount()];
if (mCursor.moveToFirst())
{
for (int i = 0; i < mCursor.getCount(); i++)
{
my[i] = mCursor.getString(columnIndex);
mCursor.moveToNext();
}
}
m=0;
int subtasks=mCursor.getCount();
int j;
for(j=0;j<=subtasks;j++){
mCursor=mDbHelper.fetchSubTask(id, my[j]);// fetching each time the task with the unique id( from the array)
//and father_id=id
LinearLayout list = (LinearLayout)v.findViewById(R.id.linear); // fill a textview of the list with one more textview
list.removeAllViews();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// for (Music music : albums.get(position).musics) {
View line = inflater.inflate(R.layout.tasks_row, null);
/* nested list's stuff */
list.addView(line);
}
m++;
}
this.mCursor.moveToNext();
// }
私は、タスクで満たされたテーブルを持つデータベースを持っています。ネストを実現するために、すべてのタスクには一意のIDと父親のIDがあります。私の問題は、カーソルが返すデータを適切に保存できず、arrayOutOfboundsExceptionが発生することです。これが私のコードです。前もって感謝します
private static final String DATABASE_CREATE =
"create table tasks (_id integer primary key autoincrement, "
+ "title text not null,"
+"location text not null, "
+ "body text not null , "
+" goaldate text not null , "
+" absolutedate text not null , "
+"currentdate text not null , "
+"prio text not null, "
+"done text not null, "
+"category text not null, "
+"timespent text not null, "
+"pososto text not null,"
+"father text not null);";
// fetch all tasks(tasks and subtasks)
public Cursor fetchTasks() {
return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
KEY_BODY,KEY_location , KEY_GOAL_DATE,KEY_ABSOLUTE_DATE, KEY_DATE_CURRENT ,KEY_PRIO,KEY_DONE, KEY_CATEGORY,KEY_TIME_SPEND,KEY_POSOSTO, KEY_FATHER},null, null, null, null, null);
}
//fetch subtasks of a task, given the father's key
public Cursor fetchSubTasks(String id) {
return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
KEY_BODY,KEY_location , KEY_GOAL_DATE,KEY_ABSOLUTE_DATE, KEY_DATE_CURRENT ,KEY_PRIO,KEY_DONE, KEY_CATEGORY,KEY_TIME_SPEND,KEY_POSOSTO, KEY_FATHER}, KEY_FATHER + " LIKE" + "'"+ id+"'", null, null, null, null);
}
//fetch a subtask
public Cursor fetchSubTask(String fid,String uid) { // tropopoihsh ths methodou wste sthn arxiki othoni na fainontai mono oi tasks
return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
KEY_BODY,KEY_location , KEY_GOAL_DATE,KEY_ABSOLUTE_DATE, KEY_DATE_CURRENT ,KEY_PRIO,KEY_DONE, KEY_CATEGORY,KEY_TIME_SPEND,KEY_POSOSTO, KEY_FATHER}, KEY_FATHER + " LIKE" + " '"+ fid +" '"+ " AND " + KEY_ROWID + " LIKE " + " '"+ uid +"' ", null, null, null, null);
}
これが私のコード@Samです。主なタスクはリストに表示され、私がやりたいことは、各タスクのサブタスクをフェッチして(複数のレベル、各サブタスクはサブタスクを持つことができます)、それらを一種のリストに表示することです(それぞれの詳細を含む特定のテキストビューを作成します)タスクにサブタスクがあるたびにタスクを実行します。ヘルプやアイデアを事前に感謝します。