I have an Activity
with 3 EditText
s and a custom view which acts a specialised keyboard to add information into the EditText
s.
Currently I'm passing the Activity
into the view so that I can get the currently focused edit text and update the contents from the custom keyboard.
Is there a way of referencing the parent activity and getting the currently focused EditText
without passing the activity into the view?
I just pulled that source code from the MediaRouter in the official support library and so far it works fine:
private Activity getActivity() {
Context context = getContext();
while (context instanceof ContextWrapper) {
if (context instanceof Activity) {
return (Activity)context;
}
context = ((ContextWrapper)context).getBaseContext();
}
return null;
}