我正在使用Xamarin.Android开发一个应用程序,它实现了一个viewpager / actionbar选项卡。当我使用相机拍照时,点按“保存”时应用程序会崩溃。出现以下错误。
System.NotSupportedException:无法在App3.ViewPagerFragment类型上找到默认构造函数。请提供缺少的构造函数。
这仅在我使用相机时发生。它会从画廊中选择一张图片就好了。我已经为ViewPagerFragment和FragmentPagerAdapter放置了代码以及我要求摄像头功能的调用。如果有人知道我做错了什么。请告诉我。我一直在靠墙砸墙试图解决这个问题。感谢。
更新:当我的应用程序出现问题时,我也发现了同样的问题。我基本上使用了这个示例应用程序并添加了相机功能。 HelloSwipeViewWithTabs
== ViewPagerFragment ==
class ViewPagerFragment : Android.Support.V4.App.Fragment {
private Func<LayoutInflater, ViewGroup, Bundle, View> _view;
public ViewPagerFragment(Func<LayoutInflater, ViewGroup, Bundle, View> view)
{
_view = view;
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
return _view(inflater, container, savedInstanceState);
}
== FragmentPagerAdapter ==
class FragmentPagerAdapter : FragmentPagerAdapter { private List<Android.Support.V4.App.Fragment> _fragmentList = new List<Android.Support.V4.App.Fragment>(); public FragmentPagerAdapter(Android.Support.V4.App.FragmentManager fm) : base(fm) {}
public override int Count
{
get { return _fragmentList.Count; }
}
public override Android.Support.V4.App.Fragment GetItem(int position)
{
return _fragmentList[position];
}
public void AddFragment(ViewPagerFragment fragment)
{
_fragmentList.Add(fragment);
}
public void AddFragmentView(Func<LayoutInflater, ViewGroup, Bundle, View> view)
{
_fragmentList.Add(new ViewPagerFragment(view));
}
}
public class ViewPageListenerForActionBar : ViewPager.SimpleOnPageChangeListener
{
private ActionBar _bar;
public ViewPageListenerForActionBar(ActionBar bar)
{
_bar = bar;
}
public override void OnPageSelected(int position)
{
_bar.SetSelectedNavigationItem(position);
}
}
public static class ViewPagerExtensions
{
public static ActionBar.Tab GetViewPageTab(this ViewPager viewPager, ActionBar actionBar, string name)
{
var tab = actionBar.NewTab();
tab.SetText(name);
tab.TabSelected += (o, e) =>
{
viewPager.SetCurrentItem(actionBar.SelectedNavigationIndex, false);
};
return tab;
}
}
==相机意图==
private void TakeAPicture() { Intent pickIntent = new Intent();
pickIntent.SetType("image/*");
pickIntent.SetAction(Intent.ActionGetContent);
Intent takePhotoIntent = new Intent(MediaStore.ActionImageCapture);
String pickTitle = "Select or take a new Picture"; // Or get from strings.xml
Intent chooserIntent = Intent.CreateChooser(pickIntent, pickTitle);
chooserIntent.PutExtra
(
Intent.ExtraInitialIntents,
new Intent[] { takePhotoIntent }
);
StartActivityForResult(chooserIntent, 0);
}