【发布时间】:2017-06-14 01:20:01
【问题描述】:
我对移动开发非常陌生,我正在尝试使用 Xamarin(visual studio) 制作一个 android 应用程序。我正在尝试将 zxing 条码扫描仪集成到我的应用程序中,并且我发现了许多将其集成到应用程序中的示例,但它们都在使用 Activity。我想使用片段而不是活动。我试图让我的片段和扫描屏幕出现,但它没有扫描任何东西。有人可以指出正确的方向。谢谢。
更新文件
这是我的 Fragment2.cs:
public class Fragment2 : Fragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate(Resource.Layout.MySettingsView, container, false);
ImageButton scanBtn = view.FindViewById<ImageButton>(Resource.Id.btnScan);
TextView results = view.FindViewById<TextView>(Resource.Id.results);
scanBtn.Click += async (sender, e) =>
{
MobileBarcodeScanner.Initialize(Activity.Application);
var scanner = new MobileBarcodeScanner();
var result = await scanner.Scan();
if (result != null)
{
return;
}
Console.WriteLine($"Scanned Barcode: {result}");
Activity.RunOnUiThread(() =>
{
results.Text = result.Text;
});
};
return view;
}
}
【问题讨论】:
标签: c# android xamarin xamarin.android