あるフィールドで並べ替えて、別のフィールドの行位置を表示することは可能ですか? たとえば、最初のフィールドに名前を入力し、2 番目のフィールドに年齢を入力し、名前で並べ替え、3 番目のフィールドに最年少から最年長の位置を表示します。
Ann 25years 2 // 2nd position in the age.
Joe 30years 3 // 3rd position in the age.
Ron 20years 1 // 1st position
「コラムエイジ」からgetpositionをつけたいのですが、可能でしょうか?
私のコード
Show_Activity
///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();
}
DBアダプタ
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;
}
.........
並べ替えを変更するボタンがあります
....
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);