Tag: kotlin anko

Anko中简单的MapRowParser是什么?

我已经阅读了Anko SQLite的文档。 我知道创建一个简单的RowParser可以通过做val rowParser = classParser<Person>() classParser是Anko-SQLite源代码中定义的一个函数。 我怎样才能得到一个简单的MapRowParser ?

如何创建像anko – DSL语法Kotlin嵌套函数回调

和anko一样,你可以这样编写回调函数: alert { title = "" message = "" yesButton { toast("Yes") } noButton { toast("No") } } 我怎样才能创建一个这样的嵌套功能? 我试图创建它像下面,但似乎并没有工作。 class Test { fun f1(function: () -> Unit) {} fun f2(function: () -> Unit) {} } 现在,如果我用这个扩展功能, fun Context.temp(function: Test.() -> Unit) { function.onSuccess() // doesn't work } 从Activity调用它: temp { onSuccess { toast("Hello") } […]

如何在anko中创建标签视图

我想要创建时间表应用程序,但是我在创建选项卡式视图时遇到了问题,如图片中所示。 我试图使用tabhost和tabwidget,但没有效果。 是否有可能,使用anko构建tabview? 图片

anko记录器库在调试版本或签名版本中记录消息

我正在尝试使用anko公共库在logcat上记录调试消息。 我想在调试版本中显示日志消息而不是在签名版本。 我知道我可以使用Proguard删除签名版本中的日志记录。 我想知道如果anko库本身只有在调试版本的情况下记录消息? 或者它在签名的版本呢? 这是anko库的Logger工具https://github.com/Kotlin/anko/blob/d5a526512b48c5cd2e3b8f6ff14b153c2337aa22/anko/library/static/commons/src/Logging.kt /** * Send a log message with the [Log.DEBUG] severity. * Note that the log message will not be written if the current log level is above [Log.DEBUG]. * The default log level is [Log.INFO]. * * @param message the function that returns message text to log. * `null` […]

进口不在Android Studio中使用

出于某种原因,非Android导入不适用于我拥有的Kotlin类。 他们使用onCreate方法在其他类中工作,但不能使用此适配器类。 在这个类中没有onCreate方法的问题是什么? 我试图使用“import org.jetbrains.anko。*”,但它不起作用。 package com.example.christophrrb.firebasetest import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter import android.widget.Button import android.widget.TextView import org.jetbrains.anko.* /** * Created by Owner on 11/10/2017. */ class ViewPeople : AppCompatActivity() { var peopleList: MutableList<Person> = mutableListOf() //This list stores all of the database value entries. val ref: DatabaseReference = FirebaseDatabase.getInstance().getReference("people") […]

包裹:无法封送价值

我和Anko一起使用Kotlin,我想发送一个玩家名单给另一个活动。 class Player(var name: String?) { var score: Int = 0 init { this.score = 0 } } 我的活动: class MainActivity: AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle ? ) { btn.setOnClickListener { val players = ArrayList <Player> () players.add(Player("John")) players.add(Player("Jeff")) startActivity <ScoreActivity> ("key" to players) } } } 当代码到达startActivity行时,我得到这个错误: java.lang.RuntimeException:Parcel:无法封送值com.yasin.myapp.Player@4e3940e 我想我的班级玩家有什么问题,但我不知道是什么。 我正在使用kotlin版本1.1.4。 有人可以帮助我吗?

如何防止对话(警报)在您使用Anko触摸外部或后退时关闭

我正在用kotlin和anko创建一个警报/对话框(下面的代码),但是当你敲门或者按回来关闭它。 这是代码 alert("TITLE") { title("Text") positiveButton("Ok") { action() } }.show() 这里是如何解决方案将在Java(没有使用anko太) dialog.setCancelable(false); // for prevent on back pressed dialog.setCanceledOnTouchOutside(false); // for prevent on touching outside 任何想法如何使用kotlin和anko实现这一点? 谢谢 :)

Kotlin&Anko协程:返回异步

在我们的项目中,我们需要获取一些数据(将被存储),然后再进行操作。 如果数据是在15分钟前获得的,我们必须刷新它。 我们正在使用Kotlin + Anko协程来做到这一点。 这个想法(假设数据是在某个时刻获得的)是: 该方法被调用并检查我们何时获得数据。 如果不到15分钟,请将其退回。 如果不是,请异步获取(这是一个网络操作),将其存储并返回。 由于在刷新数据之前我们不能做任何事情,刷新必须是同步的(通过网络操作本身是异步的)。 我们有这个代码: fun Context.retrieveInfo(api: Api?): User? { try { // For sake of simplification the real conditional check is removed if (time > 15) { val context = this val asyncUser = async(UI) { val obtainData: Deferred<Data?> = bg { api?.obtainData(sphelper.getDefaultUser(context)) } val obtainedData = storeAndRetrieve(obtainData.await(), […]

为什么我在Kotlin中使用原始的parseList函数时得不到正确的结果?

我正在学习有关Android开发人员Kotlin的Anko示例代码(本书) https://github.com/antoniolg/Kotlin-for-Android-Developers 方法1来自示例代码并覆盖parseList,但是很难理解。 所以我尝试使用方法2而不是方法1,方法2使用原始parseList函数,但是当我使用方法2时,我得到空白记录,我在方法2中做了什么错误 class DayForecast(var map: MutableMap<String, Any?>) { var _id: Long by map var date: Long by map var description: String by map var high: Int by map var low: Int by map var iconUrl: String by map var cityId: Long by map constructor(date: Long, description: String, high: Int, low: Int, iconUrl: String, […]