summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-04-26 20:21:57 +0200
committerDavid A. Madore <david+git@madore.org>2010-04-26 20:21:57 +0200
commita179d593013b67e5ef9f7b74fe50547ddd7ae512 (patch)
tree97c426aadc822fafb38c7339d6c4ee64e73d55d3
parent51301f3a00189754e58b4042364ec55618cf57e2 (diff)
downloadUnicodeMap-a179d593013b67e5ef9f7b74fe50547ddd7ae512.tar.gz
UnicodeMap-a179d593013b67e5ef9f7b74fe50547ddd7ae512.tar.bz2
UnicodeMap-a179d593013b67e5ef9f7b74fe50547ddd7ae512.zip
Remember position in list when returning.
Phew! Finding how to do this was far from obvious!
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeMapActivity.java30
1 files 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<UnicodeDisplayable> rootList
= new ArrayList<UnicodeDisplayable>(200);
- protected final List<List<UnicodeDisplayable>> stack
- = new ArrayList<List<UnicodeDisplayable>>(10);
+ protected final List<UnicodeArrayAdapter> stack
+ = new ArrayList<UnicodeArrayAdapter>(10);
+ protected final List<Integer> positionStack
+ = new ArrayList<Integer>(10);
+ protected final List<Integer> positionYStack
+ = new ArrayList<Integer>(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<UnicodeDisplayable>(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<UnicodeDisplayable> 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);