My activity has configChanges="orientation" so that the activity is
reused across orientation changes. If I have a ListPopupWindow
displaying before the orientation change, it does not get positioned
correctly after the orientation change. Is this a known issue?
Furthermore, I cannot figure how to force it to be positioned
correctly. I tried creating a new instance in #onConfigurationChanged,
but even that does not work. Any idea how I can get it to be
positioned correctly?
Thanks,
Shri
# MainActivity.java
package com.shri.helloandroid;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ListPopupWindow;
import android.content.res.Configuration;
import android.util.Log;
public class MainActivity extends Activity {
private Button button;
private ListPopupWindow popup;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.button);
popup = new ListPopupWindow(this);
popup.setWidth(200);
popup.setHeight(200);
popup.setAnchorView(button);
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (popup.isShowing()) {
if (false) {
// First attempt was to call #show again to force
recalculation of the position.
popup.dismiss();
popup.show();
} else {
// Second attempt was to try to create a new instance.
popup = new ListPopupWindow(this);
popup.setWidth(200);
popup.setHeight(200);
popup.setAnchorView(button);
popup.show();
}
}
}
public void onClick(View view) {
popup.show();
}
}
# main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Click me"
android:onClick="onClick"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en