2014-10-14 3 views
0

많은 검색에도 불구하고 나는 아마도 매우 간단한 문제 인 것에 대한 답을 찾을 수 없습니다.Xamarin Android TextView null을 반환합니다.

나는 팝업 창을 만드는 방법이 있습니다. 그런 다음 팝업 창 XML의 TextViews에 액세스하여 텍스트를 변경해야합니다. 문제는 내 textView null을 반환하는 및 따라서 최하위, countDown() 호출되는 메서드에서 텍스트를 설정할 때 null ref 예외를주는;

이것은 조각이 아닌 활동에서 실행됩니다. null ref 예외의 원칙을 이해하지만 여기서 일어나는 일이나 해결 방법을 찾을 수 없습니다. 여기에 내가

<TextView 
     android:id="@+id/test_timer" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textSize="30sp"/> 
<TextView 
     android:id="@+id/offer_expired" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textSize="30sp"/> 

감사 어떤 도움을 액세스하기 위해 노력하고있어 TextViews에 대한 XML입니다

public void clockPopup() 
    { 

    LayoutInflater inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService); 

    View myPopup = inflater.Inflate (Resource.Layout.PopUpClockTimer, null); 

    offerExpired = FindViewById<TextView> (Resource.Id.offer_expired); //returns null 
    timerDigit = FindViewById<TextView> (Resource.Id.test_timer); //returns null 

    PopupWindow popup = new PopupWindow (myPopup, ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent, true); 
    popup.ShowAtLocation (myPopup, GravityFlags.Center, 0,0); 
    popup.Update(); 


    RunOnUiThread (() => { 
     countDown(); 
    }); 


    } 

: 여기

는 방법에 대한 코드입니다.

답변

0

FindViewById가 잘못된 부모에서 검색 중입니다. 이 트릭을해야합니다 :

myPopup.FindViewById<TextView> 
+0

많은 감사합니다. 그거였다! –

관련 문제