Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 58056 articles
Browse latest View live

Xfx ComboBox for floating labels showing exception- Java.Lang.NoSuchMethodError:

$
0
0

I'm using - visual studio 2017 version 15.5.2 latest version, testing application on - Nexus5- 4.4.4 API-19 and installed latest version of xfx controls plugin.

Here is exception :neutral:
[ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.NoSuchMethodError: no method with name='setBackgroundTintList' signature='(Landroid/content/res/ColorStateList;)V' in class Landroid/view/View;
01-05 08:20:08.862 E/mono-rt (12780): at (wrapper dynamic-method) System.Object:dc6c2164-db1e-49f0-a517-fbd887a703b3 (intptr,intptr,intptr,intptr,intptr)
01-05 08:20:08.862 E/mono-rt (12780): --- End of managed Java.Lang.NoSuchMethodError stack trace ---
01-05 08:20:08.862 E/mono-rt (12780): java.lang.NoSuchMethodError: no method with name='setBackgroundTintList' signature='(Landroid/content/res/ColorStateList;)V' in class Landroid/view/View;


How to covert TextSize to FontSizes from Xamarin Android to Forms?

$
0
0

I'd like to convert a TextSize and a scaledDensity values for native Android into a FontSize value so that the text has the same size on the screen.

Currently what I do is to find a conversionScale:

float conversionScale = (float)renderer.Element.FontSize / renderer.Control.TextSize;

then I use it like this:

renderer.Element.FontSize = textSize * conversionScale;

Is it posible to compute conversionScale directly from the API instead of inferring its value from the quotient between FontSize and TextSize?

DependencyService not working (iOS 10.2, XF v2.3.3.180)

$
0
0

Hi,
I have an issue that the DependencyService is not working in iOS, while the same works perfectly in Andorid and UWP.

Example code:

using System.IO;
using Foundation;

[assembly: Xamarin.Forms.Dependency(typeof(FontHelper))]

namespace Controls.iOS
{
    public sealed class FontHelper : IFontHelper
    {
        public string GetFontPath(string fontName)
        {
            var fileName = Path.GetFileNameWithoutExtension(fontName);
            var extension = Path.GetExtension(fontName);
            return NSBundle.MainBundle.PathForResource(fileName, extension);
        }
    }
}

When calling var fontHelper = DependencyService.Get<IFontHelper>(); I only get a null result.

Registering the service manually in AppDelegate.OnActivated(UIApplication uiApplication) did not help either. I tried this variants:

DependencyService.Register<IFontHelper, FontHelper>();
DependencyService.Register<FontHelper>();

The same problem applies to ViewRenderer, which are declared as follows:

[assembly: Xamarin.Forms.ExportRenderer(typeof(TestView), typeof(TestViewRenderer))]

namespace Controls.iOS
{
    [Preserve(AllMembers = true, Conditional = false)]
    public sealed class TestViewRenderer : ViewRenderer<TestView, UIView>
    {
        [Preserve]
        public TestViewRenderer()
        {
        }
    }
}
  • According to the documentation this can happen in UWP when using Native Compilation, but shouldn't happen in iOS.
  • The setting Linker behavior is set to Don't link.
  • A Xamarin.Forms.Forms.Init(string[] assemblies) method seems to be missing. However, the Application Output (NSLog) confirms that all necessarily assemblies got loaded.
  • A imperatively method for registering ViewRenderer and EntryRenderer seems to be missing. There is only the declarative method using the ExportRendererAttribute.
  • When resolving the renderer, I get the Xamarin-renderer for the base class. So the resolving appears to work, while the registering of custom types seems to be the problem.

I am wondering if this is a problem with the DependencyService or an mistake in the documentation.

How to set the position of image in wraplayout?

$
0
0

I'm using wraplayout for galleryview and I'm facing problem , when I tapped on any image in layout it is showing image list always from 0th index.
I want to display that tapped image and rest image list from that tapped image.

Java.Lang.RuntimeException after updating App with new views

$
0
0

Hi,
in my App (v1.0), after startup (PageMainList_Appearing), I restore the last loaded item, so user can continue where he stopped. It means, it opens a TabbedPage ('PageItemTab') from the startup ContentPage ('PageMainList').

    private async void PageMainList_Appearing(object sender, EventArgs e)
    {
        if (_firstAppearing)
        {
            _firstAppearing = false;
            await LoadLastItem();
        }
    }

    private async Task LoadLastItem()
    {
        if (_lastItem != null)
            await Navigation.PushAsync(new PageItemTab(new PageItemTabViewModel(_lastItem, _viewModel)), false);
    }

It works fine, when user stats the App, it will automatically go to 'PageItemTab', instead of staying on the 'PageMainList' if _'lastItem' present.

Recently I updated my App (v2.0), added several new xamls, pages, views, etc
After updating the App (so not a new install, but updating the v1.0 from google store to v2.0), it's crashing during startup.

01-05 08:48:30.508: I/MonoDroid(14377): UNHANDLED EXCEPTION:
01-05 08:48:30.526: I/MonoDroid(14377): Java.Lang.RuntimeException: Binary XML file line #18: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true ---> Java.Lang.RuntimeException: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
01-05 08:48:30.526: I/MonoDroid(14377):    --- End of inner exception stack trace ---
01-05 08:48:30.526: I/MonoDroid(14377):   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0xc6db69b0 + 0x0001c> in <cb95916d2ab2444a9f5f028c397d3ddc>:0 
01-05 08:48:30.526: I/MonoDroid(14377):   at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <987c74f57d34446381aca87f1f37f5f4>:0 
01-05 08:48:30.526: I/MonoDroid(14377):   at Android.Runtime.JNIEnv.CallVoidMethod (System.IntPtr jobject, System.IntPtr jmethod, Android.Runtime.JValue* parms) <0xc6ac3b20 + 0x0006b> in <7c90ee8f863548b3b1b2c6032f12ed13>:0 
01-05 08:48:30.526: I/MonoDroid(14377):   at Android.Support.Design.Widget.TabLayout.SetupWithViewPager (Android.Support.V4.View.ViewPager viewPager) <0xc5cf3bd8 + 0x001d7> in <12ef52c9fdb344f58cbdf75db3fa86d8>:0 
01-05 08:48:30.526: I/MonoDroid(14377):   at Xamarin.Forms.Platform.Android.AppCompat.TabbedPageRenderer.OnChildrenCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) <0xc64d5558 + 0x00217> in <7fcbd59ddd2f4ebfb60e22f10868ab72>:0 
01-05 08:48:30.526: I/MonoDroid(14377):   at Xamarin.Forms.Platform.Android.AppCompat.TabbedPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1[TElement] e) <0xc64d4a7c + 0x00383> in <7fcbd59ddd2f4ebfb60e22f10868ab72>:0 
01-05 08:48:30.526: I/MonoDroid(14377):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) <0xc64bc114 + 0x00207> in <7fcbd59ddd2f4ebfb60e22f10868ab72>:0 
01-05 08:48:30.526: I/MonoDroid(14377):   at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) <0xc64bbcc4 + 0x0005b> in <7fcbd59ddd2f4ebfb60e22f10868ab72>:0 
01-05 08:48:30.526: I/MonoDroid(14377):   at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Support.V4.App.FragmentManager fragmentManager) <0xc649cdc4 + 0x0015f> in <7fcbd59ddd2f4ebfb60e22f10868ab72>:0 
01-05 08:48:30.526: I/MonoDroid(14377):   at Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState) <0xc64c9d98 + 0x0003b> in <7fcbd59ddd2f4ebfb60e22f10868ab72>:0 
01-05 08:48:30.526: I/MonoDroid(14377):   at Android.Support.V4.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_inflater, System.IntPtr native_container, System.IntPtr native_savedInstanceState) <0xc5f47090 + 0x000bf> in <27c17fe440cf491ba8255bcefade6e02>:0 
01-05 08:48:30.526: I/MonoDroid(14377):   at (wrapper dynamic-method) System.Object:c29447c3-0562-4939-813f-8da619914dcf (intptr,intptr,intptr,intptr,intptr)
01-05 08:48:30.526: I/MonoDroid(14377):   --- End of managed Java.Lang.RuntimeException stack trace ---
01-05 08:48:30.526: I/MonoDroid(14377): android.view.InflateException: Binary XML file line #18: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
01-05 08:48:30.526: I/MonoDroid(14377): Caused by: android.view.InflateException: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
01-05 08:48:30.526: I/MonoDroid(14377):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-05 08:48:30.526: I/MonoDroid(14377):     at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
01-05 08:48:30.526: I/MonoDroid(14377):     at android.support.design.widget.TabLayout$TabView.update(TabLayout.java:1531)
01-05 08:48:30.526: I/MonoDroid(14377):     at android.support.design.widget.TabLayout$TabView.setTab(TabLayout.java:1484)
01-05 08:48:30.526: I/MonoDroid(14377):     at android.support.design.widget.TabLayout$TabView.access$700(TabLayout.java:1348)
01-05 08:48:30.526: I/MonoDroid(14377):     at android.support.design.widget.TabLayout.createTabView(TabLayout.java:799)
01-05 08:48:30.526: I/MonoDroid(14377):     at android.support.design.widget.TabLayout.newTab(TabLayout.java:500)
01-05 08:48:30.526: I/MonoDroid(14377):     at android.support.design.widget.TabLayout.populateFromPagerAdapter(TabLayout.java:773)
01-05 08:48:30.526: I/MonoDroid(14377):     at android.support.design.widget.TabLayout.setPagerAdapter(TabLayout.java:764)
01-05 08:48:30.526: I/MonoDroid(14377):     at android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:716)
01-05 08:48:30.527: I/MonoDroid(14377):     at md5270abb39e60627f0f200893b490a1ade.FragmentContainer.n_onCreateView(Native Method)
01-05 08:48:30.527: I/MonoDroid(14377):     at md5270abb39e60627f0f200893b490a1ade.FragmentContainer.onCreateView(FragmentContainer.java:51)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:495)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.support.v7.app.AppCompatActivity.onPostResume(AppCompatActivity.java:168)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.app.Activity.performResume(Activity.java:7125)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3821)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3885)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3051)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.app.ActivityThread.-wrap14(ActivityThread.java)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.os.Handler.dispatchMessage(Handler.java:102)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.os.Looper.loop(Looper.java:154)
01-05 08:48:30.527: I/MonoDroid(14377):     at android.app.ActivityThread.main(ActivityThread.java:6776)
01-05 08:48:30.527: I/MonoDroid(14377):     at java.lang.reflect.Method.invoke(Native Method)
01-05 08:48:30.527: I/MonoDroid(14377):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
01-05 08:48:30.527: I/MonoDroid(14377):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)

If I do an uninstall/re-install, it's ok.
If I upgrade v1.0 -> v2.0, crash.
If I don't call 'LoadLastItem', it works fine.

So I can only guess, something is messed up with some v1.0 locally cached xaml binary(is there such thing at all?), and after upgrade to v2.0, it tries to use the v1.0 cached view pages, but it's not matching anymore, as new views are introduced in v2.0.
And if I do an un/re-install, it will also remove all cached view data, etc, so it works fine.

But what can I do with it? Users will not uninstall/re-install, they will upgrade (obviously).
Do you have any idea what is going on, and what can I do?

How to set xamarin forms android app auto run on background?

$
0
0

I want to set an application thats run automatically in background when user turn on mobile,In xamarin forms

How to do this?

Showing duplicate required permission in Xamarin Forms

$
0
0

Need help !!!
Let me know how to fix this issue.

Unable to build the app for iOS using Xamarin.Forms

$
0
0

Received the following exception while trying to build the app for iOS.

/Users/CName/Movies/root/packages/Xamarin.Build.Download.0.4.7/build/Xamarin.Build.Download.targets(3,3): Error: Could not find a part of the path "/Users/CName/Movies/root/ProjName/ProjName.iOS/GMps-2.5.0/Maps/Frameworks/GoogleMaps.framework/GoogleMaps".
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0015e] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.IO/FileStream.cs:223
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.IO/FileStream.cs:91
at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
at System.IO.File.OpenRead (System.String path) [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.IO/File.cs:350
at Xamarin.Build.Download.BaseXamarinBuildResourceRestore.LoadResource (System.String resourceFullPath, System.String assemblyName) [0x00000] in :0
at Xamarin.Build.Download.XamarinBuildiOSResourceRestore.LoadResource (System.String resourceFullPath, System.String assemblyName) [0x00000] in :0
at Xamarin.Build.Download.BaseXamarinBuildResourceRestore.MergeResources (Mono.Cecil.IAssemblyResolver resolver, System.String originalAsmPath, System.String mergedAsmPath, System.String assemblyName, System.Collections.Generic.List`1[T] resourceItems) [0x00089] in :0 (ProjName.iOS)


How to create an indicator like a badge inside buttons or images

$
0
0

I have an App. When i open my App i made login and after login open a MainPage. Inside mainpage i have 5 buttons or 5 images(I don't still know). This App consume a webservice. This web service has 5 methods(All get). So i have a method custo. If result this custo method is 876, then in the button/images called Custo should appear like a badge with the value inside 876. It isn't notification, only a visual indicator and i prefer like a badge. How do i do this?

Xamarin WebView inside TableView lost value

$
0
0

I have a WebView filled with an HTML code that came from database.

This WebView is inside a TableView.

This is the XAML code:

        <TableView Intent="Form" HasUnevenRows="True" Margin="0,0,0,0">
            <TableRoot>

                <!--#region Nota-->
                <TableSection Title="{core:Translate LblNota}">
                    <ViewCell>
                        <ViewCell.View>
                            <StackLayout>
                                <Label BackgroundColor="Purple" Text="{Binding NotaRigaHtml}" Style="{StaticResource LblDescrizione}" />
                                <WebView IsEnabled="False" HeightRequest="200" Source="{Binding NotaRigaHtml}"/>
                            </StackLayout>

                        </ViewCell.View>
                    </ViewCell>
                </TableSection>
                <!--#endregion-->

                <!--#region Lista Tecnici -->
                <TableSection Title="{core:Translate Tecnici}">
                    <ViewCell>
                        <ViewCell.View>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>

                                <ListView Grid.Row="0" Grid.Column="0" x:Name="ListaTecniciIntervento" HasUnevenRows="True" SeparatorVisibility="None" ItemsSource="{Binding ListaTecnici}" HeightRequest="{Binding AltezzaListaTecnici}">
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <view:TecniciInterventoViewCell Pagina="{x:Reference RigaDettaglioPage}" />
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                            </Grid>
                        </ViewCell.View>
                    </ViewCell>
                </TableSection>
                <!--#endregion-->

                <!--#region Passaggio successivo-->
                <TableSection Title="{core:Translate LblPassaggioSuccessivo}">
                    <ViewCell>
                        <ViewCell.View>
                            <Grid Style="{StaticResource GridPadding}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>

                                <Label Text="{core:Translate LblProgressStatus}"  Grid.Row="0" Grid.Column="0" />
                                <Picker Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3"/>
                                <Label Text="{core:Translate LblProgressStatusLevel}"  Grid.Row="1" Grid.Column="0" />
                                <Picker Grid.Row="1" Grid.Column="1" />
                                <Label Text="{core:Translate utente}"  Grid.Row="1" Grid.Column="2" />
                                <Picker Grid.Row="1" Grid.Column="3" />
                                <Label Text="{core:Translate LblProgressStatusInstallatore}"  Grid.Row="2" Grid.Column="0" />
                                <Picker Grid.Row="2" Grid.Column="1" />
                                <Label Text="{core:Translate LblProgressStatusTecnico}"  Grid.Row="2" Grid.Column="2" />
                                <Picker Grid.Row="2" Grid.Column="3" />
                            </Grid>
                        </ViewCell.View>
                    </ViewCell>
                </TableSection>
                <!--#endregion-->

            </TableRoot>
        </TableView>

When the WebView go off the screen, the values disappears.

How can I avoid this behavior?

Why the WebView is cleared?

Thank you!

enter image description here

EDIT:
I have find that the problem is the ListView.

When an Item of the ListView is outside of the screen, this problem is triggered, but I can't solve :(

Bar Code Reader in xamarin form Pcl project

$
0
0

@JasonAwbrey‌ @YoeriVanDamme‌

hi

I'm new in Xamarin . I'm wrote my first app in Xamarin up to 95% , without mvvm. I create classes an call on by one

Now I'm need QR code scanner & I found this .

I read sample but i don't know what can I do ?

I don't have any knowledge about MVVM.

I Whan Call Scanner in button click .

please help me I should give project in 2days.

`

    buttonScan.Click += (sender, e) => {

        // call scanner here, 
    };

`

Custom Entry Renderer Text not working

$
0
0

Entry renderer on ios is not working.

I created a custom entry renderer to display a bottom border. The problem is that it does not display the text or clicking on the entry does not display the keyboard. Is this a bug in Forms?

Unable to reference Microsoft.WindowsAzure.Storage.DataMovement in PCL

$
0
0

I can reference the package Microsoft.Azure.Storage.DataMovement in NuGet and seems to install OK.
There were initially some dependency errors, but cleared those up. However the I cannot reference the DataMovement library.

My PCL is profile '.NETPortable,Version=v4.5,Profile=Profile111', is this a .NET Standard only library?

This has been vexing me for a while so any help appreciated

System.Net.Http Could not install package 'System.Net.Http 4.3.0'. You are trying to install this pa

$
0
0

Could not install package 'System.Net.Http 4.3.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile259'

Last week I created an application and installed System.net.http via nuget.

This week I tried the same. I know I'm pushing my luck to expect it to work twice but I am a beginner at Xamarin.

Why does this happen?

I have circumvented the problem by installing Microsoft.Net.Http.

But the issues with Xamarin are tedious.

Any reason iOS AutomationIds/AccessibilitiyIdentifiers should be different on simulator vs. device?

$
0
0

I see many differences with AccessibilityIdentifiers on iOS between a simulator build vs. device build. Attached are two debug printouts with my iOS UI hierarchy and their AccessibilityIdentifiers. simulator output shows many AccessibilityIdentifiers while device build shows none. Any ideas?


xaml doesnt find RadioButton or RadioGroup

$
0
0

I have this problem, where when i type it doesnt show up to choose from. When i type in Button or Label ect. it works but there are somehow no RadioButtons to add.

I wanna create an Crossplatfrom app and i did it in the Portable class.

How to prepopulate database in an iOS/Android App?

$
0
0

Hey, guys. I'm working on an Xamarin.Forms app for iOS and Android that needs to read a prepopulated database file (about 350KB of info) that has multiple tables. I'm using the Nuget Package sqlite-net-pcl, and right now I'm going through two problems:
1. Is it possible to read a file with multiple tables? What I've done is create a model for each one and instantiating all the tables, for example:
public ObservableCollection<MapCoord> coords { get; set; }
And in the constructor:
mapdatabase.CreateTable();
this.coords = new ObservableCollection<MapCoord>(mapdatabase.Table<MapCoord>());
And then to search the table:
var query = from coord in mapdatabase.Table()
where coord.map_coord_type_id == -1
select *;
Is this correct?

  1. How can I save the file in the Resources folder, either in the iOS or the Android project, and read it correctly? Right now what I am doing is (for Android):

    public class SQLiteMapAndroid : ISQLiteMap
    {
    public SQLiteConnection GetMapConnection ()
    {
    var sqliteFileName = "map_old.db3";
    string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
    var path = Path.Combine(documentsPath, sqliteFileName);

            Console.WriteLine(path);
            if (!File.Exists(path))
            {
                var s = Android.App.Application.Context.Resources.OpenRawResource(Resource.Raw.map_old);
    
                // create a write stream
                FileStream writeStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
                // write to the stream
                ReadWriteStream(s, writeStream);
            }
    
            return new SQLiteConnection(path);
    
        }
    
        void ReadWriteStream(Stream readStream, Stream writeStream)
        {
            int Length = 1024;
            Byte[] buffer = new Byte[Length];
            int bytesRead = readStream.Read(buffer, 0, Length);
            // write the required bytes
            while (bytesRead > 0)
            {
                writeStream.Write(buffer, 0, bytesRead);
                bytesRead = readStream.Read(buffer, 0, Length);
            }
            readStream.Close();
            writeStream.Close();
        }
    }
    

I got this code from a Todo example, and adapted bits of it. The file is in Resources/raw with "AndroidResource" Build Action.

And for iOS:

public class SQLiteMapiOS : ISQLiteMap
{
    var sqliteFileName = "map_old.db3";
    string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
    string libFolder = Path.Combine(documentsPath, "..", "Library");
    var path = Path.Combine(libFolder, sqliteFileName);

    if (!File.Exists(path))
    {
        var appdir = NSBundle.MainBundle.ResourcePath;
        var source = Path.Combine(appdir, "map_old.db3");

        File.Copy(source, path);
    }

    return new SQLiteConnection(path);
}

The file in the iOS project is in Resources with BundleResource Build Action.

When I run the app the file isn't copied, either on iOS or on Android. I've read many tutorials and can't find a solution. Can anyone shine some light over this subject? Thanks in advance.

BDP

Generic Repository Question

$
0
0

I have a Xamarin.Forms program for which I wrote a generic repository for my SQLite databases. This works great, but do you have any idea why this fails:

      public Task<T> GetDataAsync( int id )
      {
         return database.Table<T>()
            .Where( i => i.ID == id )
            .FirstAsync();
      }

While this works:

      public async Task<T> GetDataAsync( int id )
      {
         List<T> items = await database.Table<T>().ToListAsync();
         foreach ( T item in items )
         {
            if ( item.ID == id )
            {
               return item;
            }
         }
         return default( T );
      }

The first one gets the right value and then crashes.

ListView Expansion Performance Questions

$
0
0

I've been trying to create a section of my app that includes a list

I'd like each item to expand to reveal more information, and only allow one cell to be expanded at any one time

I'be mostly run into issues on iOS achieving this. All the solutions seem to cause massive visual errors (cells clipping into each other) and lag. I've even gone as far as to find a way to call UITableView.ReloadRows from the PCL when on iOS instead of ForceUpdateSize

Are there any suggested ways to achieve a decent level of performance on iOS?
Since the iOS Simulator tends have some weird visual issues, is it just the simulator?

Java.Lang.NoSuchMethodError

$
0
0

Java.Lang.NoSuchMethodError: no static method "Landroid/text/Html;.fromHtml(Ljava/lang/String;I)Landroid/text/Spanned;"

I'm getting this error on Android 6 and older. On Android 7 it works.
This is happening on a Label Renderer for Android, running this command:

Html.FromHtml(myText, FromHtmlOptions.ModeCompact)

I'm using the Xamarin.Forms version 2.3.3.180, Xamarin.Android 7.0.2.42 and Xamarin 4.2.2.11

Any ideas?

Viewing all 58056 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>