簡體   English   中英

通過F#獲取xamarin.forms中的位置信息#

[英]Get location information in xamarin.forms by F #

  1. 現在我正在考慮為 android 制作一個應用程序並想要獲取位置信息。
  2. 所以我決定使用xamarin的android sdk。
  3. 但我想使用字符串作為單位的參數,但我不確定這是不可能的還是可能的
open System
open Android.App
open Android.Content
open Android.OS
open Android.Runtime
open Android.Views
open Android.Widget
open Android.Locations

type Resources = syutoku.Resource

[<Activity (Label = "syutoku", MainLauncher = true, Icon = "@mipmap/icon")>]
type MainActivity () =
    inherit Activity ()
    let L  = ""
    let mutable count:int = 1
    let location =  new Android.Locations.Location(L)
    let lL = [L]
    let soko =  lL.[0]
    override this.OnCreate (bundle) =

        base.OnCreate (bundle)

        // Set our view from the "main" layout resource
        this.SetContentView (Resources.Layout.Main)

        // Get our button from the layout resource, and attach an event to it
        let button = this.FindViewById<Button>(Resources.Id.myButton)
        button.Click.Add (fun args -> 
            button.Text <- sprintf "%d clicks!" count
            count <- count + 1
        )
        let button_3 = this.FindViewById<Button>(Resources.Id.myButton3)
        button_3.Click.Add (fun args -> 
            button_3.Text <- printfn "%s" soko
        ) 

我在這里收到錯誤 FS0001。

我認為您想使用sprintf而不是printfn ,就像在前面的處理程序中一樣:

button_3.Text <- sprintf "%s" soko

其中,由於soko是一個字符串,因此可以簡化為:

button_3.Text <- soko

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM