Reputation: 543
I have a fragment that has a button click event, on clicking this button i need to start a FragmentActivity, but i seem to be getting errors whichever way i try to do it.
Here is my button click event in the Fragment:
myExhibitGallery.Click += delegate {
//StartActivity(typeof(MyExhibitHistoryActivity));
Intent intent = new Intent(MyExhibitHistoryActivity);
StartActivity(intent);
As you can see i've tried using two different methods (intent and StartActivity), but both throw errors.
Here is the FragmentActivity i want to start:
[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;
}
}
Can anybody show me the correct way to start the FragmentActivity please?
Upvotes: 0
Views: 4261
Reputation:
Add a using to your Fragment:
using Android.Content;
Add a function to handle the event like this:
void StartMyExhibitHistoryActivity (object sender, EventArgs e)
{
var myExhibitHistoryActivity = new Intent (this.Activity, typeof(MyExhibitHistoryActivity));
StartActivity (MyExhibitHistoryActivity);
}
And finally add the Click event:
myExhibitGallery.Click += StartMyExhibitHistoryActivity;
Upvotes: 2