Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从android中的另一个类向Acivity添加视图?_Android_Xamarin_Android Custom View - Fatal编程技术网

如何从android中的另一个类向Acivity添加视图?

如何从android中的另一个类向Acivity添加视图?,android,xamarin,android-custom-view,Android,Xamarin,Android Custom View,需要从另一个类Xamarin在android父布局中添加视图组件。下面的方法确实尝试过,但无法在没有上下文的情况下创建视图组件 如果我理解正确,请更换 homeScreenTextView = new TextView (this); 与 [谢谢]!如果你觉得我的答案有用的话,请把它当作是公认的答案! public class AddCompeonent { private TextView homeScreenTextView; public View AddedView(

需要从另一个类Xamarin在android父布局中添加视图组件。下面的方法确实尝试过,但无法在没有上下文的情况下创建视图组件


如果我理解正确,请更换

homeScreenTextView = new TextView (this); 


[谢谢]!如果你觉得我的答案有用的话,请把它当作是公认的答案!
public class AddCompeonent
{
    private TextView homeScreenTextView;
    public View AddedView(View parentView){

        LinearLayout homeLayout =(LinearLayout) parentView;
        //Create textview here
        homeScreenTextView = new TextView (this);
        homeScreenTextView.Text = "here you will load home screen";
        //Add it to the layout
        homeLayout.AddView (homeScreenTextView);
        return homeLayout;
    }
}
homeScreenTextView = new TextView (this); 
homeScreenTextView = new TextView (parentView.getContext());