Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
115 views

In Android, I am using an extension function to map a failed network response to my sealed ErrorResponse class. @JsonClass(generateAdapter = true) data class ErrorResponse( @Json(name = "code&...
tzegian's user avatar
  • 609
0 votes
0 answers
31 views

I have following signature: fun <T, R> JsonNullable<T>.map(func: (T) -> R): JsonNullable<R> { How can I restrict T and R to be non-nullable ?
gstackoverflow's user avatar
0 votes
0 answers
54 views

I am a java developer but develop Kotlin for two weeks and during test implementation I've found interesting construction : every { mockedObject.foo(arg) } returns bar I've checked every finction ...
gstackoverflow's user avatar
7 votes
1 answer
829 views

Is it possible to call an extension function from another package without importing it? Given an extension function: package ext fun Int.plusOne() = this + 1 Is there any way to call this function ...
Kolja's user avatar
  • 1,247
1 vote
1 answer
822 views

I'm using FloatArray: private val values = FloatArray(5) At some point, I need to reset each array value to zero. I tried doing it like this: values.onEachIndexed { index, value -> value[index]...
testivanivan's user avatar
  • 1,544
-1 votes
3 answers
127 views

I am new to android development please help me in creating this type design I want to add text in the center of the top borders in the card please help me or guide me to achive the same view
Vuyyururajashekar Reddy's user avatar
0 votes
0 answers
76 views

How can I write extension function in kotlin for such function: public abstract fun <T : TargetValue> getAverage(metric: StatisticsMetric, interval: DateInterval, timeUnit: TimeUnit, mode: ...
yozhik's user avatar
  • 5,114
3 votes
4 answers
7k views

What is the best way to update specific item in immutable list. For example I have list of Item. And I have several ways to update list: 1. fun List<Item>.getList(newItem: Item): List<Item&...
testivanivan's user avatar
  • 1,544
1 vote
1 answer
785 views

I am reading Kotlin in Action 2nd edition. Chapter 3 says: If the class has a member function with the same signature as an extension function, the member function always takes precedence At the ...
Kirill's user avatar
  • 8,388
0 votes
2 answers
461 views

Is it possible to set type of filterIsInstance extension at runtime. For example I have list of Item and I nee to cast my list by specific condition: fun (items: List<Item>) { items....
testivanivan's user avatar
  • 1,544
0 votes
1 answer
447 views

I want use one viewModel and observe object from one method. But I dont want write this observe method in all fragment. Only write in one place and use other fragments. I think I need fragment ...
Ahmet Yılmaz's user avatar
3 votes
2 answers
223 views

Why does this program prints kotlin.Unit when it should fail with ClassCastException at runtime? class Animal<T> { } fun <T> Animal<T>.extension(block: ()-> T){ print(...
Omkar T's user avatar
  • 903
-1 votes
2 answers
760 views

Since getParcelable is deprecated for Android Tiramisu and later i want to make an extension function to get the parcelables from my Intent through my Bundle So i have val server = if (...
james04's user avatar
  • 1,968
0 votes
1 answer
752 views

How do I add the KTX updateLayoutParams() extension to my project? When I use it, Android Studio says "Unresolved reference: updateLayoutParams" even though I added this to gradle: ...
iamhere's user avatar
  • 51
1 vote
2 answers
757 views

Probably I miss something very simple, but let's imagine I have this extension method in Kotlin: fun Any.log(message: String) { println(this.javaClass.simpleName + message) } Is it possible to ...
Goltsev Eugene's user avatar
1 vote
1 answer
575 views

I am trying to get Formatting String in AndroidViewModel by using following extension function but failed: <string name="version_text">Version %1$s</string> val versionText = ...
Sam Chen's user avatar
  • 9,118
2 votes
0 answers
563 views

I have a XML file and I want to use a text view from inside that, to the best of my knowledge, view binding can be used to access views from id using: binding = ActivityMainBinding.inflate(...
Ayush Tiwari's user avatar
1 vote
2 answers
629 views

I was following some guide(download android studio today) of kotlin and I have use the setText and it's not working. what will be the problem? package com.example.basic import androidx.appcompat.app....
kimhaju's user avatar
  • 19
0 votes
1 answer
813 views

I am learning to create extension functions in Kotlin and get success in some. I want to create 2 extension functions 1 for display Progress bar when and where ever I call that function and 2 is for ...
harsh patel's user avatar
3 votes
1 answer
741 views

It seems that a simple extension property like the following does not work. var Dog.age = 0; What is the recommended way to implement this? I have tried the following, and it worked, but this will ...
Damn Vegetables's user avatar
1 vote
1 answer
1k views

I have an extension function in kotlin to check is it a valid string or not as stated below. fun EditText.onAfterTextChanged(listener: (String) -> Unit) { addTextChangedListener(object : ...
Shailendra Madda's user avatar
0 votes
1 answer
1k views

i like to achieve this kind of code: someKindOfCode.tryCatch() i kind of created it but Any doesn't do the job and don't put the code inside of tryCatch private fun Any.tryCatch() { try { ...
Alireza Mahfouzian's user avatar
0 votes
1 answer
197 views

I have a custom dialog in my android project and it was working fine. After I removed kotlin extension from the project, I have modified my code as follows but there is some issue with the Views in ...
Codist's user avatar
  • 779
2 votes
1 answer
3k views

I'm trying to convert a CompletableFuture<Optional<T>> to a Flow<T?>. The extension function I'm trying to write is fun <T> CompletableFuture<Optional<T>>....
Matthew Adams's user avatar
0 votes
1 answer
328 views

I am trying to achieve Intent Activity Utils as extended functions in Kotlin. They will start activities from other Activity/Fragment. Please suggest to me the best way to do that(). I tried to solve ...
Red Coder's user avatar
  • 145

1
2 3 4 5
7