Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid getPosition and sorting
    text
    copied!<p>Is it possible to sort by one field and view row position of another field. For example, having names in the first field and age in the second field Order By name and view in a third field a position from youngest to oldest.</p> <pre><code>Ann 25years 2 // 2nd position in the age. Joe 30years 3 // 3rd position in the age. Ron 20years 1 // 1st position </code></pre> <p>I would like to have getposition from "column age", is it possible?</p> <p>My code</p> <p>Show_Activity</p> <pre><code>///ON RESUME @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); datasource.open(); Cursor cursor = datasource.Query(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.swimm_pos) { rowcounter = cursor.getPosition()+1; String s = String.valueOf(rowcounter); TextView tv = (TextView)view; tv.setBackgroundColor(0xFF558866); tv.setText(s); return true; } return false;} }); this.setListAdapter(adapter); datasource.close(); } </code></pre> <p>DBAdapter</p> <pre><code>public Cursor Query(String filter) { Cursor cursor = database.rawQuery ("select _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); return cursor; } ......... </code></pre> <p>and I've buttons to change sort</p> <pre><code>.... switch (v.getId()) { case R.id.btn_sort_date: filter = "swimm_date"; datasource.open(); cursor = datasource.Query(filter); adapter = new SimpleCursorAdapter( this, R.layout.list_layout, cursor, columns, to); </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