I want to load a resource in a top level function using Class.getResourceAsStream(). Is there any way to get a reference to the class that the top level function will be compiled into so that I can write, for example Answer Another way I found is to declare a local class or an anonymous object inside a top level function
Tag: kotlin
Return interface implementation with Kotlin and lambda
I have this simple interface : This interface is used in one function of a class : My question is : is there a way to simplify the return statement with a lambda ? I try some stuff like this but it doesn’t work : EDIT : Kotlin supports SAM interfaces now so declaring it like so : allows us
Kotlin: Cannot import-on-demand from object
I am trying to make a library where you can call functions of an object through “static imports” (import-on-demand in Kotlin). Unfortunately Kotlin seems to have a limitation as seen below. Why is this a limitation? Is there anything I can do to get around it? (I’ve tried using a class with a companion object and in that case the
How can I change the Kotlin compiler version on IntelliJ?
In IntelliJ you can set the target Java version like this: Unfortunately I don’t see a place where I can do the same for Kotlin. This makes it not possible for me to use Quasar-Kotlin. I want to switch to M14 even though I have 1.0 beta installed. How can I change back? After changing the build.gradle file back to
Does proguard converts all enums to int or needs to be configured for this
Does proguard automatically converts enums to integer for memory optimization or I have to configure it to do this? If I do have to configure what is the configuration? Answer The optimization is listed on ProGuard’s optimizations page. It appears to be one of the default optimizations, but it (like other optimizations) can be specified explicitly if you need more
How to use Lambda expression to make Java method calls less verbose in Kotlin?
Can the below function be less verbose with a Lambda expression? How can I trim it down? It is calling the FilenameFilter.accept() Java method. Answer I’m not certain about the Kotlin syntax, but you can certainly trim it down by returning the boolean expression directly, eliminating the if: I believe the Kotlin lambda syntax would look like this: Edit: removed
Hide keyboard when navigating from a fragment to another
I have a Fragment that contains an Edit Text. When the Edit Text is pressed, the keyboard is being shown. When pressed the Save button in the upper corner, the application returns to the previous fragment, but the keyboard persists. I would like the keyboard to be hidden when navigating to the previous fragment. Please, note that I tried this
Android Get Current timestamp?
I want to get the current timestamp like that : 1320917972 Answer The solution is :
How to hide the soft keyboard inside a fragment?
I have a FragmentActivity using a ViewPager to serve several fragments. Each is a ListFragment with the following layout: When starting the activity, the soft keyboard shows. To remedy this, I did the following inside the fragment: I save the incoming ViewGroup container parameter from onCreateView as a way to access the window token for the main activity. This runs