2015-04-14 24 views
0

使用過Android Studio解僱我有它加載在一個方法訪問popupWindow從不同空

... 
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE); 
View popupView = layoutInflater.inflate(R.layout.orderup, null); 
final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); 
... 
popupWindow.showAsDropDown(findViewById(R.id.posMain), 50, -1*(height-50)); 

一旦運行有多個按鈕,用戶會點擊把那個任務完成的彈出窗口。當完成時,我想關閉popupWindow。它如何使用popupWindow,即使它在一個不同的無效方法中使用。

回答

1

聲明你popupwindow添加活動

private PopupWindow popupWindow; 

的頂部和比你的方法內部

popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); 

,比解僱該PopupWindow你可以打電話

popupWindow.dismiss(); //Dismiss PopupWindow 

if(popupWindow != null){ popupWindow.dismiss(); } //Check if PopupWindow is active, if it is, than close it.