There were problems with the implementation of the proposed solutions from StrikeForceZero and Luke Sleeman, so I wanted to contribute. I am sure that just something is missing me, so the reviews will be very grateful.
I have done the following:
Create a style using the provided PopupTheme, direct copy / paste:
<style name="PopupTheme" parent="android:Theme.Holo.Light.Dialog"> <item name="android:windowIsFloating">false</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowSoftInputMode">stateAlwaysHidden</item> <item name="android:windowActionModeOverlay">true</item> <item name="android:windowIsTranslucent">true</item> </style>
Add the showAsPopup () method as a method in the fragment that will open the fake dialog fragment, direct copy / paste:
private void showAsPopup(Activity activity) {
Create an instance of the new action with a simple call to new (), and then pass it to the showAsPopup () method:
DialogTestActivity test = new DialogTestActivity(); showAsPopup(test);
For testing (I was just trying to confirm that I could open the activity represented as a dialog with the action bar), I used an extremely simple test, stolen directly from the api demo button view (for the layout file, see the buttons_1.xml file in the api examples) :
public class DialogTestActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.buttons_test); } }
Unfortunately, every time I tried this, I get an unspecified null pointer exception on the first call, activity.requestWindowFeature (Window.FEATURE_ACTION_BAR);
04-29 16:39:05.361: W/System.err(15134): java.lang.NullPointerException 04-29 16:39:05.361: W/System.err(15134): at android.app.Activity.requestWindowFeature(Activity.java:3244) 04-29 16:39:05.371: W/System.err(15134): at packagenameremovedforlegalreasons.classname.showAsPopup(classname.java:602) 04-29 16:39:05.371: W/System.err(15134): at packagenameremovedforlegalreasons.classname.onMapLongClick(classname.java:595) 04-29 16:39:05.371: W/System.err(15134): at com.google.android.gms.maps.GoogleMap$5.onMapLongClick(Unknown Source) 04-29 16:39:05.371: W/System.err(15134): at com.google.android.gms.internal.k$a.onTransact(Unknown Source) 04-29 16:39:05.381: W/System.err(15134): at android.os.Binder.transact(Binder.java:310) 04-29 16:39:05.381: W/System.err(15134): at com.google.android.gms.maps.internal.IOnMapLongClickListener$Stub$Proxy.onMapLongClick(IOnMapLongClickListener.java:93) 04-29 16:39:05.381: W/System.err(15134): at maps.isa(Unknown Source) 04-29 16:39:05.381: W/System.err(15134): at maps.yvd(Unknown Source) 04-29 16:39:05.381: W/System.err(15134): at maps.y.bf.onLongPress(Unknown Source) 04-29 16:39:05.381: W/System.err(15134): at maps.dvonLongPress(Unknown Source) 04-29 16:39:05.381: W/System.err(15134): at maps.dhc(Unknown Source) 04-29 16:39:05.381: W/System.err(15134): at maps.dhc(Unknown Source) 04-29 16:39:05.381: W/System.err(15134): at maps.djhandleMessage(Unknown Source) 04-29 16:39:05.391: W/System.err(15134): at android.os.Handler.dispatchMessage(Handler.java:99) 04-29 16:39:05.391: W/System.err(15134): at android.os.Looper.loop(Looper.java:137) 04-29 16:39:05.391: W/System.err(15134): at android.app.ActivityThread.main(ActivityThread.java:5041) 04-29 16:39:05.391: W/System.err(15134): at java.lang.reflect.Method.invokeNative(Native Method) 04-29 16:39:05.391: W/System.err(15134): at java.lang.reflect.Method.invoke(Method.java:511) 04-29 16:39:05.391: W/System.err(15134): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 04-29 16:39:05.391: W/System.err(15134): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 04-29 16:39:05.391: W/System.err(15134): at dalvik.system.NativeStart.main(Native Method)
As you can see from the stack trace, the intended behavior is to open the window by long clicking on the GoogleMap instance (using MapFragments from API 2). So my first thought was that because of the attempt to open from the fragment, a problem arose, so I transferred the call back to my own activity. The same error, the same no additional information.
My best guess at this point was that calling new () did not create an instance of the class / view enough to make calls to change its view. It turns out that this is at least somewhat true, since migrating the view modification code into activity and just opening the operation normally works:
Defiant activity:
public void openMapDialog() { Intent intent = new Intent(this, DialogTestActivity.class); startActivity(intent); }
New class code:
public class DialogTestActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
So, I think that all I do is find out that if you want to do what the above indicators offer, you cannot just activate new () activity and call showAsPopup (). Perhaps this is my inexperience with Android, but although it seems a little obvious, it also seems natural to interpret showAsPopup () as being called by the current view, not the created view, as you are passing an instance of the activity (which would be this if it were to be done in onCreate (), as I did).
So, if the goal is to call showAsPopup () in the active creation , and not the active created , it is not clear how to get an instance of the Activity that can be modified earlier by calling onCreate (). The problem is that you cannot call things like requestWindowFeature () after calling setContentView () ( example ), which is a problem since it is usually called in onCreate ().
Again, if there is an easy / better way to do this, I really appreciate the feedback. We hope this helps people who want to use this approach.