获取TextView以便在其他类中编辑

时间:2015-05-22 13:28:47

标签: c# android xamarin findviewbyid

我以编程方式创建了TextView,如何使用TextView来更改文本?

代码

protected override void OnCreate(Bundle bundle){
        base.OnCreate(bundle);

        var layout = new LinearLayout(this);
        layout.Orientation = Orientation.Vertical;

        var relativeLayout = new RelativeLayout(this);
        layout.AddView(relativeLayout);

        TextView textViewTime = new TextView(this);
        textViewTime.Text = "00:00:00";
        textViewTime.Id = 1;
        relativeLayout.AddView(textViewTime);
        ...
}

public class MyScrollView : HorizontalScrollView

    {
        ...

        protected override void OnScrollChanged(int l, int t, int oldl, int oldt)
        {                
             TextView tv = (TextView)FindViewById(1); //returns null
             ...
        }
}

0 个答案:

没有答案