Xamarin Android TextView返回null

Xamarin Android TextView返回null,android,null,textview,xamarin,android-viewgroup,Android,Null,Textview,Xamarin,Android Viewgroup,尽管进行了大量的研究,我还是找不到一个很简单问题的答案 我有一个创建弹出窗口的方法。然后,我需要访问弹出窗口XML的文本视图并更改文本。问题是我的textView返回null,因此当我尝试在底部调用的方法countDown()中设置文本时,会出现null ref异常 这是在活动中运行的,而不是在片段中运行的。我理解null-ref异常的原理,但不知道这里发生了什么或如何修复它 以下是该方法的代码: public void clockPopup() { LayoutInflater

尽管进行了大量的研究,我还是找不到一个很简单问题的答案

我有一个创建弹出窗口的方法。然后,我需要访问弹出窗口XML的文本视图并更改文本。问题是我的textView返回null,因此当我尝试在底部调用的方法countDown()中设置文本时,会出现null ref异常

这是在活动中运行的,而不是在片段中运行的。我理解null-ref异常的原理,但不知道这里发生了什么或如何修复它

以下是该方法的代码:

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 ();
    });


    }
public void clockPopup()
{
LayoutInflater充气器=(LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
查看myPopup=inflater.Inflate(Resource.Layout.PopUpClockTimer,null);
offerExpired=findviewbyd(Resource.Id.offer_expired);//返回null
timerDigit=findviewbyd(Resource.Id.test_timer);//返回null
PopupUpWindow popup=新的PopupUpWindow(myPopup,ViewGroup.LayoutParams.WrapContent,ViewGroup.LayoutParams.WrapContent,true);
popup.ShowAtLocation(myPopup,重力梯度中心,0,0);
Update();
RunOnUiThread(()=>{
倒计时();
});
}
下面是我试图访问的文本视图的xml

 <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"/>


非常感谢您的帮助。

您的FindViewById正在错误的家长中搜索。这应该可以做到:

myPopup.FindViewById<TextView>
myPopup.findviewbyd