anko

Why does Kotlin for Android Developers (the book) need to add extensions parseList again?

馋奶兔 提交于 2019-12-13 13:13:39
问题 I know Anko provides the functions parseSingle, parseOpt and parseList , I don't understand why the code of Android Developers (the book) need to design extensions parseList again. Could you tell me? Thanks! 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 $

How to delete rows in SQLite with multiple by where args using Anko?

时光总嘲笑我的痴心妄想 提交于 2019-12-13 09:18:50
问题 I hope to delete a row by _id, I hope to delete multiple rows by where args using Anko too. I have read the article at https://github.com/Kotlin/anko/wiki/Anko-SQLite#updating-values, but I have no result, could you help me? 回答1: First off, using the update method is wrong. Deleting is not the same as updating. Updating in SQL means changing the value of one or more fields in a row. What you are looking for is the delete method dbHelper.delete(TABLE_NAME, whereClause="Your actual where

Android Spinner not responding to clicks, does not close and OnItemSelectedListener does not fire off

喜欢而已 提交于 2019-12-12 03:39:52
问题 I am developing an app in Kotlin (if you don't know about kotlin I am sure you can still help with your Android/Java experience) Details: I have a Spinner in there my app.Though it is not responding to clicks once it pops up and even shows some weird views. And because of that the OnItemSelected listener is never fired either. I start the method to update the spinner from an AsyncRealm call. Here's the code: This whole function runs, the spinner is not null, after attaching the listener, it

Kotlin / Anko button onClick not working

风流意气都作罢 提交于 2019-12-11 05:46:59
问题 I'm fairly new to Kotlin, and I'm using Anko DSL (with some XML) to generate an alert. My issue is, the onClick{ ... } function doesn't happen when I click the button. Everything else works fine, it's just this one issue fab.setOnClickListener { view -> alert { title = "Add Board" customView { include<View>(R.layout.alert_xml) { this.spinner.adapter = adapter info("Alert loaded") val boardSpinner = this.spinner val boardText = this.board_text positiveButton("OK") { onClick { info("Testing") }

'receiver type mismatch' with Fragment and Anko toast

蓝咒 提交于 2019-12-11 04:18:37
问题 I am trying to use Jetbrains' Anko library to easily display an Android toast message in my app. Here is the relevant code snippet: val message : CharSequence = "Recycled: ${holder.taskEditText.text}" (tasksFragment as Fragment).toast(text = message) and the error: Error:(80, 45) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public inline fun Fragment.toast(text: CharSequence): Unit defined in org.jetbrains.anko public inline fun

Can't Call StartActivityForResult in Anko

£可爱£侵袭症+ 提交于 2019-12-11 03:35:47
问题 I'm pretty new to android, and I'm trying to learn it with kotlin. In this code mHelp.setOnClickListener {context.startActivity<HelpActivity>()} mSettings.setOnClickListener { context.startActivityForResult<LocalSettingsActivity>( LOCAL_SETTINGS_REQUEST, "coords" to this.board.mCoords, "drag" to this.mWhiteStones[0].drag ) } the call to startActivity works fine, but I get a syntax error on the call to startActivityForResult . The error says that it's a receiver type mismatch, and that the

Anko 0.8 - unresolved lparams reference

 ̄綄美尐妖づ 提交于 2019-12-07 02:57:49
问题 The main question is: is lparams simply gone from Anko, or am I doing something terribly wrong? The following snippet fails to compile: verticalLayout { }.lparams(width = matchParent, height = matchParent) { topMargin = dip(10) } While this works without any problems: verticalLayout { layoutParams = LinearLayout.LayoutParams(matchParent, matchParent).apply { topMargin = dip(10) } } I wouldn't mind the second option too much, but you have to specify the layout type when generating the params,

Anko 0.8 - unresolved lparams reference

大城市里の小女人 提交于 2019-12-05 07:59:29
The main question is: is lparams simply gone from Anko, or am I doing something terribly wrong? The following snippet fails to compile: verticalLayout { }.lparams(width = matchParent, height = matchParent) { topMargin = dip(10) } While this works without any problems: verticalLayout { layoutParams = LinearLayout.LayoutParams(matchParent, matchParent).apply { topMargin = dip(10) } } I wouldn't mind the second option too much, but you have to specify the layout type when generating the params, which can get a bit tiresome (and is also more brittle than the original solution). I haven't found

What is the correct way of using Anko Coroutines extensions?

孤街浪徒 提交于 2019-12-05 07:15:34
问题 So I am migrating an example app from RxJava to Kotlin/Anko Corountines and I am wondering if I am doing the best (first) approach of it: fun getPopulationList() { val ref = asReference() async(UI) { try { ref().setCurrentState(ViewState.State.LOADING) val background = bg { repository.populationResponse().execute().body() } ref().let { it.response = background.await() it.mvpView?.onGetData(it.response) it.setCurrentState(ViewState.State.FINISH) } } catch (e: Exception) { e.printStackTrace()

Accessing views from the Activity with Anko

不问归期 提交于 2019-12-03 14:33:19
I know I can use an id attribute with Anko to identify a view: class MainActivityUI : AnkoComponent<MainActivity> { override fun createView(ui: AnkoContext<MainActivity>) = with(ui) { frameLayout { textView { id = R.id.text } } } } Then obtain it in the Activity using the find() function (or by using Kotlin Android Extensions): class MainActivity : AppCompatActivity() { private val textView by lazy { find<TextView>(R.id.text) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) MainActivityUI().setContentView(this) textView.text = "Hello World" } } But I