目前,我有一個按鈕,一個Linear Layout
內,像這樣:單擊按鈕時顯示PopupWindow?
我也有一個createPopup擴展(單擊該按鈕時確實執行)。
public void createPopup(View view) {
}
我試圖在其中創建一個PopupWindow
與TextView
。然後我叫showAtLocation(parent, gravity, x, y)
其中parent
是根LinearLayout
。 gravity
是Gravity.BOTTOM
,x
和y
都被設置爲10
。
當我點擊按鈕時,我收到了一個IllegalStateException
錯誤,我撥打了showAtLocation()
。這裏是createPopup()
功能:
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.");
}
我想知道的是:
- 是什麼錯誤呢?
- 它爲什麼會出現?
- 我該如何解決?
- 如何創建出現在一個按鈕的點擊一個簡單的彈出窗口?*
*我希望能夠創建一個函數,其中至少需要一個參數(這將是一個String
),然後創建一個包含String
的彈出窗口,以及一個關閉彈出窗口的按鈕。
編輯:不知道這是否是連接至彈出的問題,但是當我運行應用程序,我得到這個錯誤:
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
第二個編輯:我已經加入了相關的代碼上面。
發佈錯誤的完整堆棧跟蹤。包括錯誤消息,這很重要。 – JoxTraex
我不知道我是否能夠重現它,但我可以嘗試。 –
當給出一個錯誤時,請確保有五個完整的堆棧跟蹤,對於理解正在發生的事情非常有幫助。 – JoxTraex