0

我有一個片段,有一個按鈕單擊事件,點擊這個按鈕,我需要啓動一個FragmentActivity,但我似乎得到錯誤,無論我試圖做到這一點。Xamarin Android的 - 從片段開始片段活動

這是在我的片段按鈕單擊事件:

myExhibitGallery.Click += delegate { 

    //StartActivity(typeof(MyExhibitHistoryActivity)); 

    Intent intent = new Intent(MyExhibitHistoryActivity); 
    StartActivity(intent); 

正如你可以看到我已經用兩種不同的方法(意向和StartActivity)試過了,但都拋出錯誤。

這是我要開始FragmentActivity:

[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; 
     } 
    } 

誰能告訴我正確的方式開始FragmentActivity好嗎?

回答

1

一個使用您的片段地址:

using Android.Content; 

添加一個函數來處理這樣的事件:

void StartMyExhibitHistoryActivity (object sender, EventArgs e) 
{ 
    var myExhibitHistoryActivity = new Intent (this.Activity, typeof(MyExhibitHistoryActivity)); 
    StartActivity (MyExhibitHistoryActivity); 
} 

最後放入Click事件:

myExhibitGallery.Click += StartMyExhibitHistoryActivity; 
+0

謝謝非常! – 2014-10-30 08:44:41

+0

不客氣! :) – 2014-10-30 09:09:58