2016-09-12 2 views
0

어제부터이 문제를 파악하려고 노력했지만 아무데도 못 가고 있습니다. 자습서는 popupwindow dismiss 함수가 버튼으로 호출되는 것을 보여줍니다. 그러나 팝업 윈도우를 생성하는 MenuItem을 가지고 있습니다. 윈도우 안에는 취소 버튼이 있습니다. 취소 버튼을 누르면 창을 닫으려고합니다. 취소 버튼을 누를 때 다음은 코드안드로이드의 메뉴 항목에서 팝업 창을 닫는 방법

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    Intent intent; 
    switch (item.getItemId()) { 
     case R.id.ResetP: 
      passwordWindow(); 
      break;} 

passwordWindow()

private void passwordWindow() 
{ 
    layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE); 
    ViewGroup container = (ViewGroup) layoutInflater.inflate(R.layout.password_layout,null); 

    popupWindow = new PopupWindow(container,(int)(width * .6),(int)(height*.3),false); 
    popupWindow.showAtLocation(relativeLayout, Gravity.NO_GRAVITY,(int)(width * .2),(int)(height *.3)); 

    Button btn = (Button) findViewById(R.id.btn_cancel);//This button is in password_layout.xml file 
    btn.setOnClickListener(new Button.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      popupWindow.dismiss(); 
     } 
    }); 
} 

내 암호 창에 OK 버튼을 가지고 있으며, 취소 버튼, 나는 창을 닫으려는 코드입니다 그러나이 오류를 얻을

하여 java.lang.NullPointerException : 널 산부인과에 '무효 android.widget.Button.setOnClickListener (android.view.View에서 $ OnClickListener를)'가상 메서드를 호출하는 시도 이것은 내 머리를 꺼내하고있다

ject 참조는, 누군가가 당신이 다음 올바른 내 대답을 찾을 경우

답변

3
Button btn = (Button)container.findViewById(R.id.btn_cancel);//This button is in password_layout.xml file 

용기 .findViewById ...

+0

추가 내게 감사 도와주세요 수 있습니다 친절하게 받아들이십시오! – PriyankaChauhan

관련 문제