Questions tagged [anko]

Anko is a deprecated JetBrains library for Android application development

Anko is JetBrains library for Android application development (wrapper for Android SDK for Java), written in .

It was deprecated on the 1st of December 2019 and its use is no longer recommended.

258 questions
167
votes
13 answers

Kotlin addTextChangeListener lambda?

How do you build a lambda expression for the EditText addTextChangeListener in Kotlin? Below gives an error: passwordEditText.addTextChangedListener { charSequence -> try { password = charSequence.toString() } catch (error:…
LEMUEL ADANE
  • 8,336
  • 16
  • 58
  • 72
17
votes
1 answer

Call a default constructor from another one in Kotlin

In Kotlin, when a class has multiple constructors how can we call the designated (coming from iOS world I could not find a better name) constructor from within another constructor. Let me show you an example final class LoadingButton: LinearLayout…
apouche
  • 9,703
  • 6
  • 40
  • 45
15
votes
5 answers

How to reference other views in Anko DSL?

I'm using Anko in my Android project, but I don't know how can it reference the child views I created in the DSL when the referenced view is not at the same level where I reference it. The following code works: alert { customView { val…
Marvin
  • 1,726
  • 1
  • 17
  • 25
14
votes
3 answers

How to use Anko DSL inside a Fragment?

The Github wiki page show this example to be used in Activity instance: override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) verticalLayout { padding = dip(30) editText { hint =…
akhy
  • 5,760
  • 6
  • 39
  • 60
13
votes
2 answers

Android KTX or Anko

I'm a little confused about the advantages and disadvantages of using Android KTX vs Anko. Because both libraries are trying to achieve the same end goal, and the line between them it's getting a little bit blurry to the point, in some cases, the…
Arturo Mejia
  • 1,862
  • 1
  • 17
  • 25
12
votes
2 answers

Create a custom View/ViewGroup class in Anko DSL

I want to create a custom View which is just a wrapper of some Android Views. I looked into creating a custom ViewGroup which manages the layout of it's child views, but I don't need such complexity. What I basically want to do is something…
Suhair Zain
  • 403
  • 4
  • 15
12
votes
2 answers

Horizontal LinearLayout in Anko

What is a good way to do a horizontalLayout in anko / kotlin ? verticalLayout works fine - could set orientation on it but it feels wrong. Not sure what I am missing there.
ligi
  • 39,001
  • 44
  • 144
  • 244
11
votes
2 answers

How to create Kotlin DSL - DSL syntax Kotlin

As with anko you can write callback functions like this: alert { title = "" message = "" yesButton { toast("Yes") } noButton { toast("No") } } How can I create a nested functions like that? I tried creating…
kirtan403
  • 7,293
  • 6
  • 54
  • 97
10
votes
2 answers

Kotlin coroutine flow example for Android button click event?

I used to use Channel to send out click event from Anko View class to Activity class, however more and more Channel functions are marked as deprecated. So I wanted to start using Flow apis. I migrated code below: private val btnProduceChannel =…
Zouyiu Ng
  • 193
  • 1
  • 12
9
votes
1 answer

Anko dialog button title

With Anko, I can write something like this for showing dialog: alert("Dialog title") { yesButton {} noButton {} }.show() How can I set a title for the button? noButton {title = "title"} Unfortunately, it doesn't work.
glnix
  • 126
  • 1
  • 1
  • 8
9
votes
2 answers

Anko toast() method causes java.lang.NoSuchMethodError when called from Fragment

I'm having following error when I'm calling toast("Toast's message text") from Android Fragment: java.lang.NoSuchMethodError: No virtual method getActivity()Landroid/app/Activity; in class Landroid/support/v4/app/Fragment; or its super classes…
Jan Slominski
  • 2,968
  • 4
  • 35
  • 61
8
votes
4 answers

How to add custom view groups to Anko DSL?

Anko docs tell us how to add custom views to DSL. But if my custom view is a view group, problems arise. class MyFrameLayout(context: Context) : FrameLayout(context) fun ViewManager.myFrameLayout(init: MyFrameLayout.() -> Unit = {}) = ankoView({…
netimen
  • 4,199
  • 6
  • 41
  • 65
7
votes
2 answers

How can I convet MutableMap to vararg values: Pair?

The following code is from "Kotlin for Android Developers", you can access it at https://github.com/antoniolg/Kotlin-for-Android-Developers In order to insert a row data into CityForecastTable.NAME, I have to pass a vararg values by Source Code fun…
HelloCW
  • 843
  • 22
  • 125
  • 310
7
votes
2 answers

How can delete all records except latest 10 records with in Kotlin with anko?

The Code B define a Log table, I hope to clear all records except latest 10 records. At present, I list all records order by CreatedDate first, then I do a loop from 11th record to last record, and delete the record using Code A. Is there a better…
HelloCW
  • 843
  • 22
  • 125
  • 310
7
votes
1 answer

What is a simple MapRowParser in Anko?

I have read the docs for Anko SQLite. I know that creating a simple RowParser iscan be done by doing val rowParser = classParser() The classParser is a function defined in the Anko-SQLite source code. How can I get a simple MapRowParser?
HelloCW
  • 843
  • 22
  • 125
  • 310
1
2 3
17 18