https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
android
  • g

    Giulio

    07/23/2018, 8:24 PM
    I'm looking at this example https://github.com/android10/Android-CleanArchitecture-Kotlin for me it is interesting because it is based on viewmodel pattern I see it uses livedata, observe... (ok where can I learn about this livedata programming style?) but I would have expected to see the binding like
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@{user.firstName, default=my_default}"/>
    where are they in such project? Thanks in advance for your hint!
    :google: 1
    :stackoverflow: 1
    g
    • 2
    • 1
  • u

    ursus

    07/24/2018, 10:59 PM
    in fragments, what kind of properties do you use for view scoped things? Like adapters, and actual views .. private val adapter: Adapter? = null and then !! everywhere?
    g
    • 2
    • 95
  • a

    Ayden

    07/25/2018, 5:49 AM
    Then I wil receive the error state that binding not found.
    g
    • 2
    • 13
  • j

    jermainedilao

    07/25/2018, 7:09 AM
    Hi! can someone enlighten me why this returns false?
    "hello world".matches(Regex("([A-Za-z])"))
    l
    r
    +2
    • 5
    • 7
  • a

    Ayden

    07/25/2018, 8:46 AM
    Guys. What is the difference between model and viewModel?
    :stackoverflow: 6
    t
    • 2
    • 1
  • r

    rCorbellini

    07/25/2018, 11:46 AM
    I am looking for a practical way to convert json string to a map using kotling (I do not have a data class for it as it will be mutable)
    t
    g
    • 3
    • 4
  • a

    aprilledaughn

    07/25/2018, 2:01 PM
    Hey everyone 😊 We just published a report at Instabug that digs into the last 6 years of our data. We looked at 100 million bug reports from 15 billion sessions, 1 billion devices, and 30,000 mobile apps! This was our first time diving into our data and tbh most of the findings are pretty high level BUT we have so much info that no other company has and there's a lot more we can learn... so it would be great if anyone could take a few minutes to check out the report and share feedback about what kind of questions we should ask next year. What insights would you like to know about aggregate trends in mobile bugs? 🙏 http://bit.ly/2LN8szv
    c
    d
    a
    • 4
    • 4
  • k

    kevin.cianfarini

    07/25/2018, 10:33 PM
    Is media player the preferred option we have for streaming audio right now?
    v
    • 2
    • 1
  • s

    stegod10

    07/26/2018, 8:28 AM
    Looking for your suggestion. I just want to draw a path on map and then directive people for that rotate.
    m
    • 2
    • 1
  • a

    Alin B.

    07/26/2018, 12:02 PM
    Let's say I have a class like
    class Event(val actionId:Int, arg1:String, arg2: Int, arg3:MyClass, arg4:String)
    but when I use the class, most likely I'll need
    Event(actionID, oneOfTheArgs)
    l
    c
    • 3
    • 44
  • s

    Slackbot

    07/27/2018, 7:51 AM
    This message was deleted.
    g
    a
    • 3
    • 4
  • a

    ahegazy

    07/27/2018, 11:33 AM
    For me 2️⃣ has an advantage because of the
    OnClick
    annotation and also the ability to use it in any class like a
    ViewHolder
    for example
    a
    • 2
    • 2
  • s

    sindrenm

    07/27/2018, 12:08 PM
    I prefer 1️⃣ because it Just Works™ out of the box and is dead simple to use. However, it does “require” me to give the views IDs in camelCase in the layouts, which I am fine with personally, but I know many others don't like it. With snake_case IDs in layout files, I think I'd prefer 5️⃣, which is what we use at work. We defined a simple
    find
    extension on
    View
    that just encapsulates lazily finding the view through `lazy`:
    fun <T : View> View.find(id: Int) = lazy(LazyThreadSafetyMode.NONE) { findViewById<T>(id) }
    Usage:
    <Button id="@+id/some_button" />
    class SomeView : View {
      private val someButton: Button by find(R.id.some_button)
    }
    r
    g
    • 3
    • 2
  • j

    jw

    07/27/2018, 12:12 PM
    That's kotterknife. It's a bad idea.
    :trollface: 2
    🤔 1
    😮 2
    r
    • 2
    • 1
  • e

    Erfan

    07/27/2018, 6:29 PM
    hi guys, I have a free function like this:
    fun addQueryStrings(keyValues: Map<String, String>, baseUrl: String): String {
        var url = baseUrl + "?"
        val firstKey = keyValues.keys.first()
    
        keyValues.forEach { key, value ->
            if (key != firstKey) { url += "&" }
    
            url += "$key=$value"
        }
    
        return url
    }
    and I've received several crash report with this error:
    Fatal Exception: java.lang.NoClassDefFoundError
    blah.blah.blah.DataLayer.APICommunicatorKt.addQueryStrings
    What is wrong here? Is there anything wrong with using free function here? (note: it does not happen on all devices)
    m
    • 2
    • 1
  • t

    tschuchort

    07/28/2018, 9:18 AM
    Are there other methods in the file?
    e
    • 2
    • 1
  • a

    Adewoyin David

    07/28/2018, 8:58 PM
    Please where is the best tutorial on kotlin for a newbie
    a
    • 2
    • 2
  • s

    Slackbot

    07/29/2018, 7:23 AM
    This message was deleted.
    r
    u
    a
    • 4
    • 3
  • h

    Harun

    07/29/2018, 10:56 AM
    Any good tutorial for MVVM+ retrofit 2 in Kotlin without dagger and data binding for Android
    m
    g
    +2
    • 5
    • 13
  • m

    Mark Gilchrist

    07/30/2018, 6:43 AM
    Does anyone know of a good place to start if you want to implement flatbuffers in kotlin (android client) and php (server)?
    r
    • 2
    • 2
  • a

    Ayden

    07/30/2018, 7:14 AM
    May I know why I cannot use the
    .put
    function in the
    for
    loop?
    y
    • 2
    • 2
  • a

    Ayden

    07/30/2018, 7:14 AM
    val parameterObject = element?.asJsonObject
    val parameters: Map<String, List<String>> = HashMap()
    for (entry in parameterObject?.entrySet().orEmpty()) {
        val key = entry.key
        val value = entry.value.asString
        parameters.put(key, value)
    }
    l
    a
    t
    • 4
    • 12
  • u

    ursus

    07/30/2018, 10:51 PM
    Hey, why do @IntDef have to be Long? wtf
    t
    j
    • 3
    • 9
  • t

    thymecypher

    07/31/2018, 2:03 AM
    @neuber You need to import the package to use it in another source file.
    n
    • 2
    • 7
  • f

    Francesco megna

    07/31/2018, 9:48 AM
    Hi guys, i have a question about viewModel and fragment, how i can share the same viewModel between more fragments?
    h
    s
    a
    • 4
    • 5
  • s

    Sangeet

    07/31/2018, 12:44 PM
    I want to know whether kapt support incremental build and dagger supports that ?
    g
    • 2
    • 13
  • r

    rCorbellini

    07/31/2018, 7:51 PM
    can i apply a delegate on view visibility on element in activity ? (i need make some validation before apply visibility to view)
    r
    • 2
    • 2
  • m

    muralimohan962

    08/01/2018, 6:22 AM
    How to write a static block in kotlin classes?
    w
    c
    r
    • 4
    • 8
  • p

    Paul Woitaschek

    08/01/2018, 8:15 AM
    Someone has the same problem that as of the latest android 3.2 betas everything in modules is just displayed as unrecognized?
    g
    • 2
    • 1
  • a

    Ayden

    08/01/2018, 11:57 AM
    How to replace this
    if
    statement with Alvis Operator?
    if (element == null) {
        return null
    }
    val validationObject = element.asJsonObject
    val validation: MutableMap<String, String> = HashMap()
    for (entry: Map.Entry<String, JsonElement> in validationObject.entrySet()) {
        val key: String = entry.key
        val value: String = entry.value.asString
        validation.put(key, value)
    }
    l
    • 2
    • 1
Powered by Linen
Title
a

Ayden

08/01/2018, 11:57 AM
How to replace this
if
statement with Alvis Operator?
if (element == null) {
    return null
}
val validationObject = element.asJsonObject
val validation: MutableMap<String, String> = HashMap()
for (entry: Map.Entry<String, JsonElement> in validationObject.entrySet()) {
    val key: String = entry.key
    val value: String = entry.value.asString
    validation.put(key, value)
}
l

Lucas Ł

08/01/2018, 12:02 PM
?:
(`e`lvis operator) gives you either a default value or default behaviour https://kotlinlang.org/docs/reference/null-safety.html#elvis-operator The only thing I can see from your snippet that can be null is
element
val validationObject = element?.asJsonObject ?: JsonObject()
val validation: MutableMap<String, String> = HashMap()
for (entry: Map.Entry<String, JsonElement> in validationObject.entrySet()) {
    val key: String = entry.key
    val value: String = entry.value.asString
    validation.put(key, value)
}
if you don't want the code below do an 'empty run' you can also just do something like:
val validationObject = element?.asJsonObject ?: return
if your function doesn't return any value
View count: 2