mercredi 25 mars 2015

getting tasks starting from same date and bringing the minimum duration one task top of the list

I am making an agenda management application for android, i have calculated the duration of each tasks i am inserting, but now i want that tasks which have minimum duration and starting from same date and time shows top of the list, mean i get notification of that task first. This is my database file,please help me out, thanks.



public class SamaDb {
public static final String Row_Id = "rowId";
public static final String Task_Title = "taskTitle";

public static final String Start_Date = "startDate";
public static final String End_Date = "endDate";

public static final String Start_Time = "startTime";
public static final String End_Time = "endTime";

public static final String Description = "description";
public static final String Days_Difference = "days_difference";
public static final String Hours_Difference="hours_difference";
public static final String Minutes_Difference="minutes_difference";

private static final String myDb = "databaseName";
private static final String Table_Task = "tableName";
private static final int Version = 1;

private DbHelper helper;
private final Context ourContext;
private SQLiteDatabase ourDataBase;

private static class DbHelper extends SQLiteOpenHelper {
public DbHelper(Context context)
{
super(context, myDb, null, Version);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + Table_Task + " (" +
Task_Title + " TEXT NOT NULL, " +
Start_Date + " TEXT NOT NULL, " +
End_Date + " TEXT NOT NULL, " +
Start_Time + " TEXT NOT NULL, " +
End_Time + " TEXT NOT NULL, " +
Description + " TEXT NOT NULL, " +
Days_Difference + " TEXT NOT NULL, "+
Hours_Difference + " TEXT NOT NULL,"+
Minutes_Difference + " TEXT NOT NULL);"
);

}
// TEXT NOT NULL);"
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + Table_Task);
onCreate(db);
}
}
public SamaDb(Context c){
ourContext=c;
}
public SamaDb Open() throws SQLException{
helper= new DbHelper(ourContext);
ourDataBase=helper.getWritableDatabase();
return this;
}
public void close(){
helper.close();
}
public long createEntry(String str_task_title,String str_start_date, String str_end_date,
String str_start_time,String str_end_time,
String str_Task_Description,String str_days_difference,String str_hours_difference,String str_minutes_difference) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(Task_Title, str_task_title);
cv.put(Start_Date, str_start_date);
cv.put(End_Date, str_end_date);
cv.put(Start_Time, str_start_time);
cv.put(End_Time, str_end_time);
cv.put(Description, str_Task_Description);
cv.put(Days_Difference,str_days_difference);
cv.put(Hours_Difference,str_hours_difference);
cv.put(Minutes_Difference,str_minutes_difference);
// cv.put(Difference, duration);
return ourDataBase.insert(Table_Task,null,cv);
}
public String getData() {
// TODO Auto-generated method stub
String[] columns = new String[]{Task_Title,Start_Date,End_Date,
Start_Time,End_Time,Days_Difference,Hours_Difference,Minutes_Difference,Description};
Cursor c=ourDataBase.query(Table_Task,columns, null,null,null,null,Days_Difference+" DESC");
String result = "";


int iTitle=c.getColumnIndex(Task_Title);
int int_start_date=c.getColumnIndex(Start_Date);
int e_Date=c.getColumnIndex(End_Date);
int int_start_time=c.getColumnIndex(Start_Time);
int int_end_time=c.getColumnIndex(End_Time);
int int_description=c.getColumnIndex(Description);
int int_days_difference=c.getColumnIndex(Days_Difference);
int int_hours_difference=c.getColumnIndex(Hours_Difference);
int int_minutes_difference=c.getColumnIndex(Minutes_Difference);

for(c.moveToFirst();!c.isAfterLast();c.moveToNext()){
result=result + c.getString(int_description) + "\n" + c.getString(int_start_date) +
" " + c.getString(int_start_time) + "\nTo " + c.getString(e_Date) + " " + c.getString(int_end_time)
+"\n " +c.getString(int_days_difference)+ " Day/s, "+c.getString(int_hours_difference)+" Hour/s and "
+c.getString(int_minutes_difference)+" Minute/s \n"+
c.getString(iTitle) + "\n \n";

}
return result;

}



  1. List item


Aucun commentaire:

Enregistrer un commentaire