2012-12-23 4 views
0

아무 것도없는 IME 서비스 (화면 키보드)에서 팝업 창이 나타나게하려고합니다. popUp.showAtLocation (layout, Gravity.CENTER, 0, -100)을 호출 할 때 "Windowmanager $ BadTokenException : Window를 추가 할 수 없습니다 - 토큰 null이 유효하지 않습니다." 관련 활동이없는 서비스에서 팝업 창을 여는 것이 약간 이상한 일임을 알고 있습니다. 가능합니까? 어떤 도움을 주시면 감사하겠습니다IME에서 PopupWindow 만들기 : BadTokenException

public void initiatePopupWindow() 
{ 
    try { 

     LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View layout = inflater.inflate(R.layout.popup_layout,null); 

     // create a 300px width and 470px height PopupWindow 
     popUp = new PopupWindow(layout, 300, 470, true); 
     popUp.showAtLocation(layout, Gravity.CENTER, 0, -100); 


     Button cancelButton = (Button) layout.findViewById(R.id.popup_cancel_button); 
     cancelButton.setOnClickListener(inputView.cancel_button_click_listener); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

:

여기 내 코드입니다. 고마워요

답변

0

나는 문제를 발견했습니다 - 나는 레이아웃을 사용하여 팝업을 그리고 부모와 같은 레이아웃을 사용하려고했습니다. 해결 방법은 부모를 다른보기로 설정하는 것입니다. 팝업을 만들기 전에 뷰가 생성되었는지 가져 오기 (예 : 처리기/실행 가능 파일을 사용하여)도 가져 오는 것이 확인되었습니다.

public void initiatePopupWindow() 
{ 
    try { 
     Log.i("dotdashkeyboard","initiatePopupWindow (from IME service)"); 
     LayoutInflater inflater = (LayoutInflater) this.getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View layout = inflater.inflate(R.layout.popup_layout,null); 

     // create a 300px width and 470px height PopupWindow 
     popUp = new PopupWindow(layout, 300, 470, false); 
     popUp.showAtLocation(inputView, Gravity.CENTER, 0, -100); 

     Button cancelButton = (Button) layout.findViewById(R.id.popup_cancel_button); 
     cancelButton.setOnClickListener(inputView.cancel_button_click_listener); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
}