如何从android中的另一个类向Acivity添加视图?
需要从另一个类Xamarin在android父布局中添加视图组件。下面的方法确实尝试过,但无法在没有上下文的情况下创建视图组件如何从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(
如果我理解正确,请更换
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());