我试图用Xamarin.Android从片段开始活动。这是片段
public class ChoirFragment : TourFragment
{
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your fragment here
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate(page, container, false);
Button button = view.FindViewById<Button>(Resource.Id.Button);
button.Click += delegate
{
var intent = new Intent(Activity, typeof(StartActivity));
StartActivity(intent);
};
return base.OnCreateView(inflater, container, savedInstanceState);
}
}
当我点击按钮时,点击什么都不做:(。
我不知道为什么调试器不会停在OnCreateView上。
如果您需要更多信息,请不要犹豫,问我。提前谢谢!
答案 0 :(得分:1)
在您的代码return base.OnCreateView(inflater, container, savedInstanceState);
中,我不知道为什么这对您加载片段视图有用,在我身边我应该返回view
进行布局。
无论如何,以下演示对我有用:
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate(Resource.Layout.Choir_Fragment, container, false);
Button button = view.FindViewById<Button>(Resource.Id.myButton);
button.Click += delegate
{
//var intent = new Intent(this.Context, typeof(StartActivity));
var intent = new Intent(Activity, typeof(StartActivity));
StartActivity(intent);
};
return view;
}
如果需要此演示,请发表评论。
答案 1 :(得分:0)
尝试将return view
更改为 "authors": [
{
"firstName": "Nigel",
"lastName": "Rees"
},
{
"firstName": "Evelyn",
"lastName": "Waugh"
}
]