xamarin.android - How to make Zebra Xing (Zxing) as subview in Xamarin Android -
in xamarin.android app, want use zxing scan barcode. want display scanner in view of activity.
code:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:weightsum="5"> <button android:text="scan default overlay" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/buttonscandefaultview" android:layout_weight="1" /> <linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/scanview" android:layout_weight="2" /> </linearlayout>
protected override void oncreate (bundle bundle) { base.oncreate (bundle); scannerfragment = new zxingscannerfragment (); scannerfragment.customoverlayview = customoverlayview; scannerfragment.usecustomoverlayview = usecustomoverlayview; scannerfragment.toptext = toptext; scannerfragment.bottomtext = bottomtext; this.fragmentmanager.begintransaction () .replace (resource.id.scanview, scannerfragment, "zxingfragment") .commit (); }
i'm getting error stating cannot convert support.v4.fragment android.app.fragment.
can advise i'm doing wrong , how should approach scanner view (of zxing) in layout of current activity.
zxingscannerfragment
derives android.support.v4.app.fragment
while activity.fragmentmanager
expects fragments derived android.app.fragment
.
now, how fix that:
inherit activity activity works android.support.v4. easiest use
android.support.v4.app.fragmentactivity
packagexamarin.android.support.v4
installedzxing.net.mobile
package dependency.when have correct activity, can use
this.supportfragmentmanager
instead ofthis.fragmentmanager
work support.v4-based fragments.
so, layout have good. code should updated like:
using android.app; using android.widget; using android.os; using zxing.mobile; using android.support.v4.app; namespace zxingsample { [activity(label = "zxing sample", mainlauncher = true, icon = "@mipmap/icon")] public class mainactivity : fragmentactivity { int count = 1; protected override void oncreate(bundle savedinstancestate) { base.oncreate(savedinstancestate); setcontentview(resource.layout.main); var scannerfragment = new zxingscannerfragment(); scannerfragment.usecustomoverlayview = false; scannerfragment.toptext = "scan code"; scannerfragment.bottomtext = "then proceed"; this.supportfragmentmanager.begintransaction() .replace(resource.id.scanview, scannerfragment, "zxingfragment") .commit(); } } }
launching app, see scanner:
Comments
Post a Comment