diff --git a/src/api-impl/android/app/Activity.java b/src/api-impl/android/app/Activity.java index 6a3750d8..9275341c 100644 --- a/src/api-impl/android/app/Activity.java +++ b/src/api-impl/android/app/Activity.java @@ -239,7 +239,9 @@ public class Activity extends ContextWrapper implements Window.Callback { public T findViewById(int id) { System.out.println("- findViewById - asked for view with id: " + id); - View view = View.view_by_id.get(id); + View view = null; + if (window.contentView != null) + view = window.contentView.findViewById(id); System.out.println("- findViewById - found this: " + view); return (T)view; diff --git a/src/api-impl/android/view/View.java b/src/api-impl/android/view/View.java index d4e4db64..b1b11086 100644 --- a/src/api-impl/android/view/View.java +++ b/src/api-impl/android/view/View.java @@ -808,8 +808,6 @@ public class View extends Object { public long widget; // pointer - public static HashMap view_by_id = new HashMap(); - private int oldWidthMeasureSpec = -1; private int oldHeightMeasureSpec = -1; private boolean layoutRequested = true; @@ -836,7 +834,6 @@ public class View extends Object { int id = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "id", 0); if (id != 0) { this.id = id; - view_by_id.put(id, this); } @@ -860,8 +857,10 @@ public class View extends Object { } public View findViewById(int id) { - /* TODO: this should probably only search among children, but the id is surely unique anyway? :P */ - return view_by_id.get(id); + if (this.id == id) + return this; + else + return null; } public void onDraw(Canvas canvas) {} @@ -946,7 +945,6 @@ public class View extends Object { public void setId(int id) { this.id = id; - view_by_id.put(id, this); } public void setOnKeyListener(OnKeyListener l) {} diff --git a/src/api-impl/android/view/ViewGroup.java b/src/api-impl/android/view/ViewGroup.java index 66563633..379fb323 100644 --- a/src/api-impl/android/view/ViewGroup.java +++ b/src/api-impl/android/view/ViewGroup.java @@ -304,6 +304,17 @@ public class ViewGroup extends View implements ViewParent, ViewManager { public void setClipToPadding(boolean clipToPadding) {} + public View findViewById(int id) { + if (this.id == id) + return this; + for (View child: children) { + View result = child.findViewById(id); + if (result != null) + return result; + } + return null; + } + public static class LayoutParams { public static final int FILL_PARENT = -1; public static final int MATCH_PARENT = -1; diff --git a/src/api-impl/android/view/Window.java b/src/api-impl/android/view/Window.java index 1d9e8cc7..867b6ddb 100644 --- a/src/api-impl/android/view/Window.java +++ b/src/api-impl/android/view/Window.java @@ -28,6 +28,8 @@ public class Window { public Window(Window.Callback callback) { this.callback = callback; + contentView = new ViewGroup(Context.this_application); + contentView.setId(android.R.id.content); } public void addFlags(int flags) {} @@ -66,7 +68,10 @@ public class Window { } public View findViewById(int id) { - return View.view_by_id.get(id); + if (contentView != null) + return contentView.findViewById(id); + else + return null; } public View peekDecorView() {