2014-03-14 2 views
2

Button과 다른 요소를 내 PopupWindow에서 가져 오는 중, debugger을 사용하여 null으로보고하겠습니까?Android 팝업 창 팝업에서 요소를 가져 오지 못함

private void initiatePopupWindow() 
     { 
      try 
       { 
        // We need to get the instance of the LayoutInflater 
        LayoutInflater inflater = (LayoutInflater) LoginActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        View layout = inflater.inflate(R.layout.activity_register,(ViewGroup) 

        findViewById(R.id.popup_element)); 
        pwindo = new PopupWindow(layout, 600, 900, true); 
        pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0); 

        btnReg = (Button) findViewById(R.id.btnReg); 
        inputName = (EditText) findViewById(R.id.name); 
        inputDOB = (DatePicker) findViewById(R.id.dob); 
        String name = inputName.getText().toString(); 

        btnReg.setOnClickListener(new View.OnClickListener() 
        { 
         @Override 
         public void onClick(View v) 
         { 


          if ( (!inputName.getText().toString().equals("")) && 
            (getAge(inputDOB.getDayOfMonth(), inputDOB.getMonth(), inputDOB.getYear()) > 15)) 
          { 
           //register user 
          } 
          else if ((inputName.getText().toString().equals(""))) 
          { 
           Toast.makeText(getApplicationContext(), 
             "Please enter your name", Toast.LENGTH_SHORT).show(); 
          } 
          else if ((getAge(inputDOB.getDayOfMonth(), inputDOB.getMonth(), inputDOB.getYear()) < 16)) 
          { 
           Toast.makeText(getApplicationContext(), 
             "You must be at least 16 to use this app", Toast.LENGTH_SHORT).show(); 
          } 
          else 
          { 
           Toast.makeText(getApplicationContext(), email, Toast.LENGTH_SHORT).show(); 



          } 

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

사람이 올바른 방향으로 날 지점 또는 내가 그들을 R.id를 사용하여 찾을 수없는 이유를 설명 할 수?

건배

업데이트 : Activity_Register.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/popup_element" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="@drawable/rounded" 
       android:orientation="vertical" 
       android:padding="10sp" > 

    <EditText 
     android:id="@+id/name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:inputType="textPersonName" 
     android:hint="@string/name" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true"> 

     <requestFocus /> 
    </EditText> 

    <DatePicker 
     android:id="@+id/dobPicker" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:calendarViewShown="false" 
     android:layout_below="@+id/dob" 
     android:layout_centerHorizontal="true"/> 

    <TextView 
     android:id="@+id/dob" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/dob" 
     android:layout_below="@+id/name" 
     android:layout_alignParentStart="true" 
     android:layout_marginTop="42dp"/> 

    <Button 
     android:id="@+id/btnReg" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="38dp" 
     android:text="@string/register" 
     android:layout_below="@+id/dobPicker" 
     android:layout_centerHorizontal="true"/> 

</RelativeLayout> 
+0

'activity_register.xml' 파일을 게시하십시오. –

답변

4

당신은 같이 얻을 수

View layout = inflater.inflate(R.layout.activity_register, 
      (ViewGroup) youractivity.this.findViewById(R.id.popup_element)); 

btnReg = (Button) layout.findViewById(R.id.btnReg); 
inputName = (EditText) layout.findViewById(R.id.name); 
inputDOB = (DatePicker) layout.findViewById(R.id.dob); 

그것은 inflated layout보기에서 오는 당신의 모든 요소 becoz 그리고 당신이 얻을 수 context을 통과해야 popup_element 레이아웃은 ViewGroup입니다.

+0

젠장, 이미 그걸 시도 했었다고 확신합니다! 많은 감사합니다 :-) – dave

+0

@dave하지만 제 경우에는 효과가 있습니다. –

+0

그것은 내 작품 에서뿐만 아니라, 난 그냥 생각했을 때 그것을 시도하지 않았을 지금, 팝업 내에서 내 발사되지 않는 내 onclick 문제가 있지만이 initiatepopup 하위 래핑되어 있기 때문에 이것이라고 생각합니다. – dave

0

사용이 layout.findViewById(R.id.popup_element)); instead of this findViewById(R.id.popup_element));

0

시도는 this처럼 popupwindow impliment합니다.