English 中文(简体)
结 论
原标题:Completion Handler Android Kotlin

如果以前曾问过这个问题,我真的会发现任何类似情况! 如果问题不成问题,I mi-SOS- 和I m 一道在安康这里损失的轨迹,我也感到担忧。

https://github.com/kittinunf/Fuel rel=“nofollow noreferer” JSON 数据来自APIC。 迅速,一些叫作“编织手”的物品,一旦功能结束,就会返回,立即在其中操作守则。 这是快速发展的一个实例:

func hardProcessingWithString(input: String, completion: (result: String) -> Void) {
    ...
    completion("we finished!")
}

我需要做的是与我在科特林的以下职能类似的事情。

fun recomendationsData() {

    Fuel.get("https://rss.itunes.apple.com/api/v1/us/apple-music/hot-tracks/10/explicit.json").response { request, response, result ->
                    println(request)
                    println(response)
                    val (bytes, error) = result
                    if (bytes != null) {
                        val str = String(bytes)
                        val obj = JSONObject(str)
                        val resultsP = obj.getJSONObject("feed")
                        val results = resultsP.getJSONArray("results")

                        for (i in 0..(results.length() - 1)) {
                            val o = results.getJSONObject(i)
                            trackName1.add(o.getString("name"))
                            trackArtist1.add(o.getString("artistName"))
                            trackImage1.add(o.getString("artworkUrl100"))
                        }
                    }
                }
}

我宣读了所谓的“召回”内容,但我确实不理解它是如何运作的,也不知道如何执行(这项任务必须按时间顺序完成)。

最佳回答

在此情况下,辛加税与迅速:

fun recommendationsData(callback: (String) -> Unit) {

Then in your function you have a function called callback that you can call with the result (change String to whatever you re returning).

然后,将你的职责从<条码>建议/条码>改为<条码>建议/条码>。

recommendationsData {
    doSomethingWith(it) // or you can get named argument
    // do some more stuff
}
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签