Xamarin Android-从Fragment启动FragmentActivity
我有一个片段,它有一个按钮点击事件,点击这个按钮我需要启动一个片段活动,但无论我以何种方式尝试,我似乎都会出错 下面是片段中的我的按钮单击事件:Xamarin Android-从Fragment启动FragmentActivity,android,android-fragments,xamarin,android-fragmentactivity,Android,Android Fragments,Xamarin,Android Fragmentactivity,我有一个片段,它有一个按钮点击事件,点击这个按钮我需要启动一个片段活动,但无论我以何种方式尝试,我似乎都会出错 下面是片段中的我的按钮单击事件: myExhibitGallery.Click += delegate { //StartActivity(typeof(MyExhibitHistoryActivity)); Intent intent = new Intent(MyExhibitHistoryActivity); StartActivity(intent)
myExhibitGallery.Click += delegate {
//StartActivity(typeof(MyExhibitHistoryActivity));
Intent intent = new Intent(MyExhibitHistoryActivity);
StartActivity(intent);
using Android.Content;
正如你所见,我尝试过使用两种不同的方法(intent和StartActivity),但都会抛出错误
以下是我想开始的片段活动:
[Activity (Label = "My Exhibit History")]
public class MyExhibitHistoryActivity : FragmentActivity
{
ViewPager _viewPager;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.MyExhibitHistory);
_viewPager = FindViewById<ViewPager> (Resource.Id.viewPager);
}
}
public class ViewFragmentAdapter: FragmentPagerAdapter
{
public ViewFragmentAdapter (Android.Support.V4.App.FragmentManager fm) : base (fm)
{
}
public override int Count {
get { return 5; }
}
public override Android.Support.V4.App.Fragment GetItem (int position)
{
return new viewerFragment();
}
}
public class viewerFragment: Android.Support.V4.App.Fragment
{
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate (Resource.Layout.myExhibitHistoryItem, container, false);
return view;
}
}
[活动(Label=“我的展览历史”)]
公共类MyExhibitHistoryActivity:FragmentActivity
{
ViewPager\u ViewPager;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.MyExhibitStory);
_viewPager=FindViewById(Resource.Id.viewPager);
}
}
公共类ViewFragmentAdapter:FragmentPagerAdapter
{
公共ViewFragmentAdapter(Android.Support.V4.App.FragmentManager fm):基本(fm)
{
}
公共覆盖整数计数{
获取{return 5;}
}
public override Android.Support.V4.App.Fragment GetItem(int位置)
{
返回新的viewerFragment();
}
}
公共类viewerFragment:Android.Support.V4.App.Fragment
{
创建视图上的公共覆盖视图(布局、充气机、视图组容器、捆绑包保存状态)
{
var view=充气机.充气(Resource.Layout.myExhibitHistoryItem,container,false);
返回视图;
}
}
有人能告诉我启动碎片活动的正确方法吗?在碎片中添加一个using:
myExhibitGallery.Click += delegate {
//StartActivity(typeof(MyExhibitHistoryActivity));
Intent intent = new Intent(MyExhibitHistoryActivity);
StartActivity(intent);
using Android.Content;
添加一个函数来处理如下事件:
void StartMyExhibitHistoryActivity (object sender, EventArgs e)
{
var myExhibitHistoryActivity = new Intent (this.Activity, typeof(MyExhibitHistoryActivity));
StartActivity (MyExhibitHistoryActivity);
}
最后添加单击事件:
myExhibitGallery.Click += StartMyExhibitHistoryActivity;