Tag: anko

为什么我在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, […]

类型干扰失败。 期望的类型不匹配:必需的字符串在Kotlin和Anko中找到pair <String,String>

我用kotlin和anko库创建了一个数据库。 我正在关注这篇文章https://antonioleiva.com/databases-anko-kotlin/我想在下面的数据库块中插入数据,但我得到一个错误 类型干扰失败。 期望的类型不匹配:必需的字符串找到对 fun insertPerson() { database.use { insert(PersonTable.Name, PersonTable.PersonName to "XX", PersonTable.Domain to "Technology", PersonTable.MobileNumber to "XXXXX") } } object PersonTable { val Name = "Person" val ID = "id" val PersonName = "person_name" val Domain = "domain" val MobileNumber = "mobile_number" } 的build.gradle apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' […]

为什么Android开发人员的Kotlin(书)需要再次添加扩展parseList?

我知道Anko提供的函数parseSingle,parseOpt和parseList,我不明白为什么Android开发人员(书)的代码需要再次设计扩展parseList。 你可以告诉我吗? 谢谢! https://github.com/antoniolg/Kotlin-for-Android-Developers/blob/master/app/src/main/java/com/antonioleiva/weatherapp/data/db/ForecastDb.kt override fun requestForecastByZipCode(zipCode: Long, date: Long) = forecastDbHelper.use { val dailyRequest = "${DayForecastTable.CITY_ID} = ? AND ${DayForecastTable.DATE} >= ?" val dailyForecast = select(DayForecastTable.NAME) .whereSimple(dailyRequest, zipCode.toString(), date.toString()) .parseList { DayForecast(HashMap(it)) } } https://github.com/antoniolg/Kotlin-for-Android-Developers/blob/master/app/src/main/java/com/antonioleiva/weatherapp/extensions/DatabaseExtensions.kt fun <T : Any> SelectQueryBuilder.parseList(parser: (Map<String, Any?>) -> T): List<T> = parseList(object : MapRowParser<T> { override fun parseRow(columns: Map<String, […]

如何设置文本,焦点,在与Kotlin Android的editText错误

我在互联网上沉重搜索如何可以在android的editText(s)上使用setFocusable() , setText() , setError()等等方法(我知道我们可以在java中使用上述方法的事实)我无法找到适合我的确切解决方案。 我正在使用1)排气为http调用2)kotlin插件为android工作室版本='1.1.3-2'3.)anko库 我在运行应用程序时遇到的问题:1.)setError()方法没有被调用。 2)我不能在editText上使用setText()和setFocus()。 请注意,我需要Kotlin中的解决方案而不是Java。 提前致谢! private fun askAppointment() { if (editTextPersonName?.text.isNullOrEmpty()) { editTextPersonName?.error ="Person Name cannot be empty." return } else if (editTextPersonMobile?.text.isNullOrEmpty()) { editTextPersonMobile?.error = "Person Mobile cannot be empty." return } else if (editTextPersonEmail?.text.isNullOrEmpty()) { editTextPersonEmail?.error = "Person Email cannot be empty." return } else if (editTextSubject?.text.isNullOrEmpty()) { […]

Kotlin anko通用选择器在提供的示例中不起作用

当使用示例中提供的anko选择器时,它不起作用 val countries = listOf("Russia", "USA", "Japan", "Australia") selector("Where are you from?", countries) { i -> toast("So you're living in ${countries[i]}, right?") } 在这里定义lambda函数时,它表示期望两种类型的参数。 (Dialoginterface和int)。 我坚持这一点。 ALOS默认的kotlin alertdialog说的是一样的东西。 任何一个人可以解决这个问题,或告诉我如何建立一个警戒对话框在kotlin选择?

在Kotlin中调用另一个构造函数

在Kotlin中,当一个类有多个构造函数时,我们怎样才能从另一个构造函数中调用指定的 (来自iOS世界,我找不到更好的名字)构造函数。 让我给你看一个例子 final class LoadingButton: LinearLayout { var text:String? = null constructor(context: Context, text: String) : this(context) { this.text = text } constructor(context: Context) : super(context) { val t = this.text this.view { button(t) { /* … */} } } } 在这里,如果我做loadingButton("TEST", {})该字符串不会传播到按钮,因为this(context)之前调用的便利构造函数的代码(对不起)。 Kotlin能解决这个问题吗? 就像是 constructor(context: Context, text: String) { this.text = text this(context) […]

如何在Kotlin anko中使用TextInputLayout和TextInputEditText

Error:(63, 13) Unresolved reference: textInputLayout Error:(64, 17) Unresolved reference: textInputEditText 当我尝试在kotlin anko中添加textInputLayout&textInputEditText时,我得到了上面的错误信息。 以下是我的代码 – private fun test(context: Context): View{ return with(context){ verticalLayout { textInputLayout { textInputEditText{} } } } }

在Kotlin和Anko中实现SQLite

我创建了如下的应用程序数据库。 我想现在插入记录和检索,因为这个链接说https://antonioleiva.com/databases-anko-kotlin/使用database.use import android.database.sqlite.SQLiteDatabase import org.jetbrains.anko.db.* class AppDbHelpler : ManagedSQLiteOpenHelper(AppApplication.instance(), AppDbHelpler.DB_NAME, null, AppDbHelpler.DB_VERSION) { companion object { val DB_NAME = "person.db" val DB_VERSION = 1 val instance by lazy { AppDbHelpler() } } override fun onCreate(db: SQLiteDatabase?) { db!!.createTable(PersonTable.Name, true, Pair(PersonTable.ID, INTEGER + PRIMARY_KEY + AUTOINCREMENT), Pair(PersonTable.PersonName, TEXT), Pair(PersonTable.Domain, TEXT), Pair(PersonTable.MobileNumber, REAL)) } override fun […]

Kotlin / anko多个异步任务

我正在寻找一种简单的方法来并行启动多个任务,并等待所有这些完成。 考虑这个C#的例子: private static void Main(string[] args) { var urlList = new[] {"http://www.microsoft.com/", "http://www.google.com/", "http://www.apple.com/" }; var result = GetHtml(urlList); } private static List<string> GetHtml(string[] urlList) { var tasks = new List<Task>(); var output = new List<string>(); foreach (var url in urlList) { var task = new Task(() => { var html = new WebClient().DownloadString(url); […]

什么是在Anko协程kotlin推迟?

在kotlin的Anko coroutines库中,有一个特性bg()用于在后台线程上轻松地执行你的代码。 在那个返回类型是Deferred 。 那么什么是延期 ? Refrence链接 (1) https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Deferred.kt (2) https://github.com/Kotlin/anko/wiki/Anko-Coroutines#bg fun getData(): Data { … } fun showData(data: Data) { … } async(UI) { val data: Deferred<Data> = bg { // Runs in background getData() } // This code is executed on the UI thread showData(data.await()) }