https://kotlinlang.org logo
Docs
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
stackoverflow
  • u

    user

    06/27/2022, 6:11 AM
    How to remove the badge from created shortcut icon in android app? How to remove the badge in app shortcut icon in android? When I create app shortcut programmatically, along with the icon specified for shortcut, app icon comes at the bottom corner of the icon. How to remove this badge from icon. ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); if (shortcutManager.isRequestPinShortcutSupported()) { ShortcutInfo pinShortcutInfo; pinShortcutInfo = new ShortcutInfo.Builder(context, "icon")...
  • u

    user

    06/27/2022, 7:51 AM
    Connect to specific bluetooth device [Kotlin] I'm, quite new to this ble stuff, I found this piece of code that shows a list of ble devices. However I'm trying to make it so that it connects to a specific device. Any guesses on what kind of options I have? private fun onBluetoothEnabled() { val bondedDevices = bluetoothAdapter?.bondedDevices if (bondedDevices != null) { val bondedAdapter = ArrayAdapter( this, android.R.layout.simple_spinner_item,...
  • u

    user

    06/27/2022, 7:51 AM
    build.gradle on project level has a new format in Android. How to change my existing gradle setup to a new one? I have been away for a year for developing Android apps. I noticed the build.gradle of project level has a new format: FROM: // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = '1.3.61' ext.retrofit_version = "2.6.0" ext.coroutines_version = "1.3.0" ext.room_version = '2.4.2' ext.glide_version = "4.8.0" ext.nav_version = '2.4.2'...
  • u

    user

    06/27/2022, 8:11 AM
    Is there findFirst with position in predicate in Kotlin I need to find first element in a list which fits predicate. But I need to check with it position in predicate. list.findXXX { index, item -> index > 19 && item.active } Is there such a function?
  • u

    user

    06/27/2022, 8:11 AM
    Null pointer exception in Kotlin (IntelliJ) Here is what I am trying to do, I want the user to enter whatever number and it should be displayed, but I am getting this error.

    https://i.stack.imgur.com/Rbxek.pngâ–¾

  • u

    user

    06/27/2022, 8:31 AM
    Best way to mock http server in spring boot with kotlin [2022] I want to test an http repository, and to do so I need to mock an HTTP server. I found this resource that goes over on one way to do so in spring boot, however, it's from 2020. I am not saying it's necessarily a bad or outdated approach, but I wanted to know if there is a more preferable or a kotlin specific way to mock HTTP server now. Any help would be appreciated.
  • u

    user

    06/27/2022, 8:31 AM
    Android - How can I make my custom view fill the whole screen? I have a custom view named FloorView. I want this Floor view to be occupying the whole screen, and I need this dynamically (maybe match_parent). I don't want to hard code the size of the view. I've tried doing this in FloorView.kt private val rectangle = RectF( ViewGroup.LayoutParams.MATCH_PARENT.toFloat(), ViewGroup.LayoutParams.MATCH_PARENT.toFloat(), 0f, 0f) I was thinking I could use the match_parent attribute, and match the ConstraintLayout of my MainActivity, but...
  • u

    user

    06/27/2022, 8:31 AM
    Empty response body when parsing API with Retrofit and Gson I used Retrofit and Gson on this project. I'm trying to login where I should get a response of the user id, faunadb_token, and also data list filled with user data. "body": "{\n \"content\": {\n \"id\": \"328803596056396364\",\n \"faunadb_token\": \"fauna fnEEnk81KUACTwSP8HIOwApJqbjNg-u4fqC9q6Da2FvPTP2esYs\",\n \"data\": {\n \"name\": \"test2\",\n \"email\": \"bowner@gmail.com\",\n \"role\": \"admin\",\n \"organization_id\":...
  • u

    user

    06/27/2022, 8:51 AM
    How to create following types of layout in android I have tried using ProgressBar or SeekBar but how to add left cut on one side and right side also

    https://i.stack.imgur.com/9zmX6.gifâ–¾

  • u

    user

    06/27/2022, 9:11 AM
    How can I pass variable of "phoneNumberState.value" from ScreenA to ScreenB in jetpack compose? I have one variable in screen A as val phoneNumberState = remember { mutableStateOf("") } and I want to pass this argument to screen B, so I try to do it on internet, there is some example, I confused how to apply, is there easy way for it? navigation: @OptIn(ExperimentalPagerApi::class) @Composable fun Navigation( startDestination: String ) { val navController = rememberNavController() NavHost(navController = navController, startDestination = startDestination) { composable("screenA"...
  • u

    user

    06/27/2022, 9:11 AM
    How to use Lambda function in Android In my application I have RecyclerView adapter and I want when click on Items, send some data to parent. I want send model and string. I write below codes, but after use show me error and I can't use this! Lambda function in adapter : private var onItemClickListener: ((UserEntity) -> Unit)? = null private var actionType: String? = null fun setOnItemClickListener(listener: (UserEntity) -> Unit, type: String) { onItemClickListener = listener actionType = type } Use this function...
  • u

    user

    06/27/2022, 9:51 AM
    How do add a database in an existing android application How do i add a database to an already existing android application .is there any possible way to create a database add it in the existing android application and it uses the application
  • u

    user

    06/27/2022, 9:51 AM
    How to extract the buffer data while recording videos in CameraX Android I am just facing a small issue while recording videos in CameraX using "Video Capture", I don't want to directly write the data into a file, instead, I wish to extract the buffer data, do some actions on it and then write that into a file. How do I extract the buffer data of the video? I would be obliged if someone could help me with this
  • u

    user

    06/27/2022, 10:31 AM
    Kotlin - categorized subenums I am trying to implement a Role class/interface/enum that I can use throughout my program. I want the roles to be somewhat categorized - I want some roles to be of type A, some roles to be of type B, and some roles to be part of multiple types. I want to be able to know all the roles from each type - so an enum/sealed class structure is the idea. I tried the following implementation - sealed interface UserRole { val roleName: String } enum class RoleA(override val roleName: String):...
  • u

    user

    06/27/2022, 11:11 AM
    Floating Action Bar (not button) in Android I am working on Floating Action Bar on top of keyboard if user clicks on one of the EditText. I couldn't start on it and that's why not have any code to present. I am confused on how to approach this problem. I am considering to use bottom sheet but I am still not getting confidence on it (I think android should have something better to use as base for this view). I don't need any code snippet but need a direction. I am new to Android and before jumping to implementation, I needed a direction...
  • u

    user

    06/27/2022, 11:11 AM
    How to set onItemTouchlistener in recyclerview in kotlin I want to perform some action in onTouch event of recyclerview item, in kotlin, but i am not able to do that. Please help.
  • u

    user

    06/27/2022, 11:11 AM
    SurfaceViewHolder.setFixedSize(width,height) not setting size to video saved in gallery I want to set the video aspect ratio to 1:1 capturing during android media recorder. Im using holder.setFixedSize in onSurfaceChanged method override fun surfaceChanged(holder: SurfaceHolder, format: Int, w: Int, h: Int) { // If your preview can change or rotate, take care of those events here. // Make sure to stop the preview before resizing or reformatting it. if (mHolder.surface == null) { // preview surface does not exist return } // stop preview...
  • u

    user

    06/27/2022, 11:11 AM
    Assertion fails on object copied using Kotlin copy This is a problem that has been really puzzling. For some reason, equals method fails here: val newItem = testPlaylistItem.copy(id = returnedItem.id, index = 0, updatedAt = newPlaylistFromDb.updatedAt) assertEquals(newPlaylistFromDb, newItem) As you can see, I'm just overwriting some properties that I know that change and I can't control (id isn't known since it's generated by the persistence and index and updatedAt are internally generated). Basically what I'm doing is ignoring them for the...
  • u

    user

    06/27/2022, 11:31 AM
    How to create iOS style SwitchCompat in Android

    https://i.stack.imgur.com/XoxPEm.pngâ–¾

    I want to create iOS style of SwitchCompat in Android like in the image above. I have tried with replacing app:track and android:thumb. However, I found out that I can't set a track width that is smaller than 2x of thumb width. Below screenshot is my attempt at Android. You can see the switch track is significantly wider than native iOS Switch. <a href="

    https://i.stack.imgur.com/YutMml.pngâ–¾

    " rel="nofollow...
  • u

    user

    06/27/2022, 11:51 AM
    Android resources.getColor() freezes code I need to add views to LinearLayout dynamically on POST request finished inside a fragment. Here is my function that creates and setups the view and returns it, then I add it to the chatsRoot via addView() method. No exceptions, but views are not added. After some debug I noticed, that in logcat there is only one message "Banner created1" and no message "Banner created2", like if the program freezed on loading the color resource. Log.d("VIEW", "Banner created1") // appears in logcat val...
  • u

    user

    06/27/2022, 11:51 AM
    Android: Custom background - rectangle with a circle cutting in the middle I'm trying to implement this view

    https://i.stack.imgur.com/bpJmn.pngâ–¾

    As you can see it had a circle cutting to the left and right of the rectangle I tried to use this code but the result was not showing the cutting circle to the left and right Is there any...
  • u

    user

    06/27/2022, 11:51 AM
    how to open a byte array as a file in it's own dedicated app [VLC for mp4,etc] without saving it locally? I'm building an app which encrypts a file and saves it in the encrypted format such that it can be opened later when required. While opening, the encrypted file is taken as a byteArray and decrypted into a new byteArray. Now, what I want is to open this new byteArray as a file keeping it's extension in mind and opening it in its dedicated app like VLC for video, any audio player for audio files, google docs for word files, etc. If possible, I don't want to save it to the device storage due to...
  • u

    user

    06/27/2022, 12:11 PM
    Use a object before initialized as other object argument I'm new to kotlin and I know that nullable are something I should'nt use as much as I would want too. So I was wondering if something like that would be possible. class Header(var next: Trailer) class Trailer(var prev: Header) fun main() { lateinit var trailer: Trailer val header = Header(trailer) trailer = Trailer(header) } Thank you for the time used to answer my question!
  • u

    user

    06/27/2022, 12:11 PM
    How to test private val callback in kotlin using mockito and robolectic? I have a private val callback, using reflection I can take the value but how to access and test the override functions and inside the functions handler is present. So here I want to test the override and handler. Using mockito and roboelctric. private val mMediaControllerCallback: MediaControllerCompat.Callback = object : MediaControllerCompat.Callback() { override fun onPlaybackStateChanged(state: PlaybackStateCompat) { mHandler!!.post { if (state !=...
  • u

    user

    06/27/2022, 12:11 PM
    How do I get and implement these animated icons in my application? From where do I get these animated icons and how can I implement them in my app? Example
  • u

    user

    06/27/2022, 12:31 PM
    Regex doesn't change string I want to remove all symbols that aren't letters or numbers, but my string isn't changed. fun main() { var testStr = "Hello, World 2022!" countWords(testStr) } fun countWords(input: String) { val regex ="""^A-Za-z0-9""".toRegex() val inputChanged = input.replace(regex, " ") println("changed input: $inputChanged") }
  • u

    user

    06/27/2022, 12:31 PM
    MediaBrowser not resuming audio but starts it from the beggining I am building an application that includes a media browser in order to play audio tracks. Whenever I want to start an activity from a fragment wanting to display a media player showing the track already playing from the fragment, the track starts from the beginning instead of resuming playing. I haven't figured out yet why. Here is my activity code: import android.content.ComponentName import android.net.Uri import android.os.Bundle import android.support.v4.media.MediaBrowserCompat import...
  • u

    user

    06/27/2022, 12:51 PM
    How to restrict Cut, Copy, Select &amp; Paste option in Android when double tap or long click the edit text view? I have checked several ways and the below is one of them that I checked. I also checked with android:longClickable="false" and android:textIsSelectable="false" in xml file. It needs to work in all the OS versions. val callback: ActionMode.Callback = object : Callback, ActionMode.Callback { override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean { menu?.apply { removeItem(android.R.id.copy)...
  • u

    user

    06/27/2022, 1:31 PM
    Android - How can I zoom in on a custom View I made using Kotlin? I have a FloorView, and within this FloorView I'll be filling it with RoomViews. Every floor has rooms. I want a functionality that can allow the user to zoom in on the floor, and see the rooms up closer. Think of it as Google maps. The earth is the floor, and the buildings/road are the rooms The floor is huge, will have many rooms, that's why I want the ability to zoom in. How can I achieve this? I want the zoom functionality to be the exact same from Google maps; using two fingers I have...
  • u

    user

    06/27/2022, 1:31 PM
    OnTextChanged triggered before writing anything Im using EditText and trying to validate it. In my validations, Im checking if the EditText is empty and if it is, shows an error. My problem is that my error is showing when the activity starts and when I didnt click anything, so is triggering before I write anything and before any text change. What I want is to show this error If I write something and then I delete all, but not when the activity is created because will always be empty. Any idea?
Powered by Linen
Title
u

user

06/27/2022, 1:31 PM
OnTextChanged triggered before writing anything Im using EditText and trying to validate it. In my validations, Im checking if the EditText is empty and if it is, shows an error. My problem is that my error is showing when the activity starts and when I didnt click anything, so is triggering before I write anything and before any text change. What I want is to show this error If I write something and then I delete all, but not when the activity is created because will always be empty. Any idea?
View count: 3