Questions tagged [kotlin-extension]

Kotlin provides the ability to extend a class with new functionality without having to inherit from the class or use any type of design pattern such as Decorator. This is done via special declarations called extensions.

333 questions
0
votes
1 answer

Fragment View is null when try to access from Activity

I have created a Fragment which is in ViewPager. Fragment is loading fine. I am using a button to swipe fragments in viewpager and before swiping, I want to check validations. So I did this in Activity : val pos: Int = viewPager.currentItem …
0
votes
4 answers

Kotlin Extensions - Inflate Custom Views

I'm new to kotlin, I Have an adapter class and I need to inflate a view. but recently I'm facing an error saying "Unresolved reference: R" Like in the image below : So, how can I inflate this view? I have imported the following: import…
Tamim Attafi
  • 2,253
  • 2
  • 17
  • 34
0
votes
4 answers

can we swap two numbers in kotlin using two variables and take input from user?

I tried it by the following program but it shows the error that kotlin variable is expected: [
0
votes
1 answer

Can I extend Comparable in Kotlin?

I wanted to implement min()/max() aliases for the Kotlin's ComparablecoerceAtLeast()/coerceAtMost(), if nothing else for the exercise of extending an Interface (I've only extended classes so far). I tried this: fun Comparable.max(other:T) :…
Travis Griggs
  • 21,522
  • 19
  • 91
  • 167
0
votes
0 answers

Android Studio doesn't highlight invalid Kotlin receiver when using @IdRes

I expected that using extension: fun @receiver:IdRes Int.findView() = findViewById(this) On resource that is not defined in R.id would highlight the call, but it doesn't: Is this a bug? EDIT Linked question and answers do not answer this…
xinaiz
  • 7,744
  • 6
  • 34
  • 78
0
votes
2 answers

Kotlin : The specified child already has a parent. You must call removeView() on the child's parent first

Can anyone tell me what is the problem. This is the code: package com.mohdjey.user.inflate import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.os.strictmode.WebViewMethodCalledOnWrongThreadViolation import…
0
votes
1 answer

Kotlin - Replace a single two-methods interface with two different one-method interfaces

First of all, I want to clarify that my questions is for a personal code-style preference. Let's say I have a method which takes an interface as parameter, and the said interface has two methods in it. In kotlin, implementing the interface…
Lampione
  • 1,622
  • 3
  • 21
  • 39
0
votes
2 answers

Break out of lambda in kotlin

I am trying to add an very useful extension method to Java’s InputStream class, since we know stream parsing requires several lines of boiler plate code and In my application we need to process stream multiple times. So far my extension function…
Manish Bansal
  • 185
  • 11
0
votes
1 answer

Kotlin Activity changes writing order from left to right to right to left (Phone w/ different language)

I have a Kotlin project in Android Studio and I developed a simple app... My real device is in a different language so when I run the app on my device all the activity is stuck to the right (like you write in Hebrew...) I want to keep the order left…
Adam
  • 299
  • 1
  • 4
  • 19
0
votes
1 answer

Kotlin represent array with boolean indexing

I want to have a 2x2 2d array of int in kotlin but the indexing should be using booleans like this: | true | false | ---------------------- true | 0 | 75 | ---------------------- false | 1 | 34 | I know I can use a 2d array of…
Jofbr
  • 455
  • 3
  • 23
0
votes
0 answers

when I choose am item from spinner it doesn't show, but its selected

I have an activity were I have to show a list of names in a spinner, the names are in a Firebase database and I managed to do that and it works just fine here is how it looks like: the items added in the spinner but after I select an item it just…
0
votes
1 answer

android studio kotlin cannot get data to display

Complete Newbie to Kotlin, trying to get three values to pass across from text boxes to another page, I am getting no errors put the info is not either being passed across or displayed I have tried for hours to get this to work with no avail.page 1…
James24
  • 73
  • 4
  • 12
0
votes
1 answer

How can I extension Java class with Kotlin to use like static fun?

public class TestA { public static void a() {} } fun TestA.b(){} How can I extension Java class with Kotlin to use like static fun ? just like TestA.b() to use this fun
wanbo
  • 868
  • 9
  • 24
0
votes
1 answer

Kotlin, how can retry request if get error when tap on button of dialog

Let imagine situation on Kotlin, when we try get request but hasn't internet connection and we get error, then show AlertDialog, and we need retry request if user click on "positive button". This method check for exist user by phone number: override…
nicolas asinovich
  • 3,201
  • 3
  • 27
  • 37
0
votes
1 answer

Kotlin, set value to TextView use callback interface

Such mini example, in Java I have: public static void getPlaceName(GoogleApiClient mGoogleApiClient, String placeId, @NonNull PlaceNameCallback callback) { Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId) …
nicolas asinovich
  • 3,201
  • 3
  • 27
  • 37