Note that there are some explanatory texts on larger screens.

plurals
  1. POget total from a sqlite string column
    text
    copied!<p>how can I add the total of column "swimm_lap" (numbers stored as string) and show it in a textview. I try to add something like ...select sum(swimm_lap) ....from</p> <p>here what I have in my adapter</p> <pre><code>public Cursor Query(String filter, String date_filter, String lap_filter) { if (date_filter == null &amp; lap_filter == null){ int sum = 0; Cursor cursor = database.rawQuery ("select sum(swimm_lap) _id,swimm_pos,swimm_date, swimm_lap,swimm_stroke,swimm_time,swimm_media,swimm_efficiency,swimm_note from swimm_table order by cast("+filter+" as integer) asc", null); if (cursor.moveToFirst()) {sum = cursor.getInt(0);} return cursor;} </code></pre> <p>and in main activity</p> <pre><code>totallap = (TextView) findViewById(R.id.total_lap); totallap.setText(String.valueOf(sum)); public void Bindadapter() { datasource.open(); Cursor cursor = datasource.Query(filter, date_filter, lap_filter); String[] columns = new String[] { "swimm_pos", "swimm_date","swimm_lap","swimm_stroke", "swimm_time", "swimm_media", "swimm_efficiency", "swimm_note" }; int[] to = new int[] { R.id.swimm_pos, R.id.swimm_date, R.id.swimm_lap, R.id.swimm_stroke, R.id.swimm_time, R.id.swimm_medialap, R.id.swimm_efficiency, R.id.swimm_note}; SimpleCursorAdapter adapter = new SimpleCursorAdapter( this, R.layout.list_layout, cursor, columns, to); adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view.getId() == R.id.total_lap) { sum = cursor.getInt(0); String s = String.valueOf(sum); TextView tv = (TextView)view; tv.setText(s); return true; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload