Sort values in child views of custom listview android -


i designing custom listview ,which has more child view

i have ideas sorting listviewdata in "asc" or "desc" order ,that retrieves data directly database , in case used customsimplecursoradapter , requires sort data in textview depending upon values is:

  1. today
  2. tomorrow
  3. more 2 days i.e; 354

customsimplecursoradapter .java

//days remaining birthday            string year=cursor.getstring(cursor.getcolumnindex(birthdayprovider.event_year));         string month=cursor.getstring(cursor.getcolumnindex(birthdayprovider.event_month));           string date=cursor.getstring(cursor.getcolumnindex(birthdayprovider.event_date));         string remainingdays=birthdaycalculation.getdaysremainingfornextbirthday(year, month, date);           calendar today=calendar.getinstance();          int cmonth=(today.get(calendar.monday)+1);          int cdate=(today.get(calendar.day_of_month));            //checking whether bd on today           if (remainingdays.equals("1") && (cdate==integer.parseint(date) && (cmonth)==integer.parseint(month))) {                                      viewholder.txtdaysremainigvalue.settextsize(typedvalue.complex_unit_sp, 20);              viewholder.txtdaysremainigvalue.settypeface(fontroboto_regular);              viewholder.txtdaysremainigvalue.settextcolor(color.parsecolor("#00cc33"));              remainingdays="today";                       }           //checking whether bd on tomorrow          else if (remainingdays.equals("1")) {                         viewholder.txtdaysremainigvalue.settextsize(typedvalue.complex_unit_sp, 17);              viewholder.txtdaysremainigvalue.settextcolor(color.parsecolor("#ff0099"));              remainingdays="tomorrow";              viewholder.txtdaysremainigvalue.settypeface(fontroboto_regular);         }          //checking how many days remaining bd          else{           remainingdays=birthdaycalculation.getdaysremainingfornextbirthday(year, month, date);           viewholder.txtdaysremainigvalue.settextsize(typedvalue.complex_unit_sp, 27);           viewholder.txtdaysremainigvalue.settextcolor(color.parsecolor("#990000"));           } 

here's screen shot link

when query database, should use "order by" clause. example, this method takes order clause last argument. don't know how store dates , times in database, if it's sqlite can recognize , provide sorting on, should work. following query columns on table named "table" no clause, no "group by" clause, no "having" clause, , order time column descending (use asc ascending if want instead):

database.query("table", null, null, null, null, null, "time desc");

edit

if can't store exact data want (in case days remaining until event), can see 2 options:

1). after getting cursor, iterate on results , compose new sorted list. make kind of model object in java, read values cursor, , sort them comparator function. @ point not use cursoradapter more. it's quite easy build own listadapter - recommend watch the world of listview

2). since query methods take strings, can compose more complicated queries sqlite provides data want (and still sort well). if times stored longs, this:

long currenttime = system.currenttimemillis(); string timeasstring = long.tostring(currenttime); string remainingtimecolumn = "(time_column - " + timeasstring + ") remaining_time";  // compose query string table = "table"; string[] columns = new string[] {"column1", "column2", ..., "columnn", remainingtimecolumn}; string order = "remaining_time asc";  // query cursor cursor = database.query(table, columns, null, null, null, null, order);  // later, remaining time cursor row long remainingtime = cursor.getlong(cursor.getcolumnindex("remaining_time")); 

in case "time_column" name of column stores event time. doing creating additional column name "remaining_time", calculated 1 of actual column values. results sorted synthesized column. cursor contain column , these values, need have proper column name access them.

since don't know details of data format, can't how query should look, idea should clear. can work out finer details here...


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -