From a179d593013b67e5ef9f7b74fe50547ddd7ae512 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Mon, 26 Apr 2010 20:21:57 +0200 Subject: Remember position in list when returning. Phew! Finding how to do this was far from obvious! --- .../android/unicodeMap/UnicodeMapActivity.java | 30 +++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java index def8537..c352b58 100644 --- a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java +++ b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java @@ -22,8 +22,12 @@ public final class UnicodeMapActivity extends ListActivity { protected final List rootList = new ArrayList(200); - protected final List> stack - = new ArrayList>(10); + protected final List stack + = new ArrayList(10); + protected final List positionStack + = new ArrayList(10); + protected final List positionYStack + = new ArrayList(10); protected void launchPopulation() { final ProgressDialog progress = new ProgressDialog(this); @@ -64,8 +68,10 @@ public final class UnicodeMapActivity extends ListActivity { launchPopulation(); for ( UnicodeCharacter.Range rng : UnicodeCharacter.Range.values() ) rootList.add(rng); - stack.add(rootList); - setListAdapter(new UnicodeArrayAdapter(this, rootList)); + UnicodeArrayAdapter rootAdapter + = new UnicodeArrayAdapter(this, rootList); + stack.add(rootAdapter); + setListAdapter(rootAdapter); final ClipboardManager cmgr = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); final Button btn = (Button) findViewById(R.id.button); @@ -94,8 +100,13 @@ public final class UnicodeMapActivity extends ListActivity { = new ArrayList(db.countRange(from,to)); for ( UnicodeCharacter ch : db.getRange(from,to) ) list.add(ch); - stack.add(list); - setListAdapter(new UnicodeArrayAdapter(UnicodeMapActivity.this, list)); + UnicodeArrayAdapter adapter + = new UnicodeArrayAdapter(UnicodeMapActivity.this, + list); + stack.add(adapter); + positionStack.add(position); + positionYStack.add(view.getTop()); + setListAdapter(adapter); } else throw new AssertionError("unknown UnicodeDisplayable"); } @@ -105,10 +116,11 @@ public final class UnicodeMapActivity extends ListActivity { @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ( ( keyCode == KeyEvent.KEYCODE_BACK) && stack.size() > 1 ) { + final ListView lv = getListView(); stack.remove(stack.size()-1); - List list - = stack.get(stack.size()-1); - setListAdapter(new UnicodeArrayAdapter(UnicodeMapActivity.this, list)); + setListAdapter(stack.get(stack.size()-1)); + lv.setSelectionFromTop(positionStack.remove(positionStack.size()-1), + positionYStack.remove(positionYStack.size()-1)); return true; } return super.onKeyDown(keyCode, event); -- cgit v1.2.3