Currently, I have a button, within a Linear Layout
, like so:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/open_popup"
android:onClick="createPopup"/>
</LinearLayout>
I also have a createPopup extension (which does indeed execute when the button is clicked).
public void createPopup(View view) {
}
I have tried to create a PopupWindow
with a TextView
within it. I then called showAtLocation(parent, gravity, x, y)
where parent
is the root LinearLayout
. gravity
was Gravity.BOTTOM
, x
and y
were both set to 10
.
When I clicked the button, I received an IllegalStateException
error where I called showAtLocation()
. Here is the createPopup()
function:
PopupWindow popUp;
LinearLayout layout;
LinearLayout main;
TextView value;
LayoutParams params;
boolean click = true;
public void createPopup(View view) {
popUp = new PopupWindow(this);
layout = new LinearLayout(this);
main = (LinearLayout) findViewById(R.id.parent);
value = new TextView(this);
if(click) {
popUp.showAtLocation(main, Gravity.BOTTOM, 10, 10);
popUp.update(50, 50, 300, 80);
click = false;
} else {
popUp.dismiss();
click = true;
}
params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
layout.setOrientation(LinearLayout.VERTICAL);
value.setText(R.string.message);
layout.addView(value, params);
popUp.setContentView(layout);
setContentView(main);
TextView status = (TextView) findViewById(R.id.status);
status.setTextSize(28);
status.setText("Status of Popup: Don't worry, you're never going to get this.");
}
What I would like to know is:
- What does that error mean?
- Why does it appear?
- How can I fix it?
- How do I create a simple popup window that appears at the click of a button?*
*I'd like to be able to create a function where it takes at least one parameter (which would be a String
), and then create's a popup window that contains that String
, as well as a button to close the popup window.
EDIT: Not sure if this is connected to the popup issue, but when I run the app, I get this error:
07-13 19:51:48.448 133-133/? E/[EGL-ERROR]: egl_image* _egl_create_image_ANDROID_native_buffer(egl_display*, egl_context*, EGLClientBuffer, EGLint*, void*):593: CHUN try create image with crop 0,0,0,0
[ 07-13 19:51:48.448 133: 133 E/ ]
CHUN map external image rgb 1024 x 600
SECOND EDIT: I've added relevant code above.