How to make clickable listview in android using kotlin - kotlin

I am new in android development with kotlin . I am trying to make clickable listview items but not getting good resource.

It's really not much different from how you'd do it in Java since Kotlin uses Java's frameworks/libraries and its JVM. Just apply the necessary Kotlin plugins and configurations in Android Studio, convert the Java code to Kotlin, and then refer to the Kotlin docs for potential bug fixes and whatnot.

Related

Is green Dao supported by kotlin?

I'm converting my existing java project into the Kotlin , while during this I come across the problem that unresolved ref to 'dao', I tried changing the sequence of greendao & Kotlin dependency as but still facing the same issue
Kotlin is 100% interoperable with Java by design, so with some tinkering you can clearly make everything work. If you post your specific problems with the code, the community might be able to help you make the conversion.

How to build Microsoft and Mac OS App with Compose for Desktop with the right approach

I need to develop a desktop app for Windows and Mac OS with Jetbrains Compose Multiplatform
I will use the Kotlin language to design the UI.
But I need guidance on following points:
Which languages will be required for the core logic / calculations / network client, etc. in the desktop app ?
Can we write the entire Microsoft desktop app in Kotlin (Compose for Desktop)
Can we use Android classes like Fragment, ViewModels, Room in Compose for Desktop ?
If we cannot use Android classes in desktop app then, where do we write the code which we write in ViewModel classes in Android ? How to structure the code and packages
What is the best architecture for Desktop app which are being built with Compose or Desktop. ?
I could not find any architecture diagram for Desktop Compose App
Can we use Jnuit and Espresso for writing UI and Instrumented tests in Compose for Desktop ?
Note:
I have gone through the official documentation of compose desktop.
I also went though the code of samples and multiple blogs, but the above queries are not answered clearly.
Hence I need your guidance
1,2 — I guess that any JVM-compatible language would be fine.
3,4 — https://github.com/JetBrains/compose-jb/discussions/1587
You should abstract from androidx ViewModel creating a pure Kotlin ViewModel delegate that can be injected into android ViewModel.
So in this case androidx ViewModel will play the role of wrapper over multiplatform implementation.
But keep in mind that there is no component's lifecycle or navigation ecosystem like in Android world. For this purpose, you can use Decompose library.
I am not an expert in Compose for Desktop, so I would prefer not to answer the last two questions. Also, I would recommend you to search for answers in the #compose-desktop channel of the Kotlin official Slack workspace(get an invite here).

Unable to import os.log in Kotlin Multiplatform

I am trying to implement kotlin multiplaform logger. During the implementation of iOS architecture, I couldn't import os.log to use os_log. How could I do this or what else can I use to log in iOS in Kotlin Multiplatform project?
The problem is that the OSLog class has only Swift API: see here. As Kotlin/Native does not provide direct interoperability, some frameworks are unavailable(see the same problem with SwiftUI for example). The best option you have out-of-the-box is to use NSLog, as Philip suggests, or to use some third-party library. There is a resource with a list of popular Kotlin Multiplatform libraries: https://github.com/AAkira/Kotlin-Multiplatform-Libraries#logging. It might be a good place to start. Two important things to note about this:
This list does not include all libraries. For sure, there are some nice libs that are not included yet.
I'm recommending it as an entry point to the community. Philips' advice is pretty good, and maybe there are some other approaches that can be seen across the libs or in the kotlinlang Slack.
You can simply use kotlin println, also in iOS part you can use platform.Foundation.NSLog for formatter output

Differences in writing Kotlin/JVM and Kotlin/JS?

I read the Big Nerd Ranch guide to Kotlin and it talked in several places about Kotlin/Java interop, but never JS or native. I already had a solid background in Java, so I have gotten used to using Java classes in my Kotlin code. I am trying to write a Kotlin program which will be run on a site where most - if not all - functionality is written in JavaScript, and I am trying to understand how to write my code to make sure that it is interoperable. Will I be able to continue using Java classes in my Kotlin/JS code? What are the differences between writing Kotlin/JVM code and Kotlin/JS code? What should a (ex-) java programmer know when learning to interop with JS using Kotlin? If there are a few chapters on this in any good books written in the recent past, that would be helpful also.
As Steve already mentioned, you can't utilise java classes in Kotlin/JS.
Think of Kotlin/JS as Typescript.
It provides a different syntax to write code that ultimately compiles to JS.
Here are the notable differences of writing Kotlin/JS code vs Kotlin/JVM code
Kotlin/JS internally uses yarn for dependency management. This enables you to depend on any javascript module available on npmjs etc (see note below)
In addition to standard library, you can also leverage other kotlin-first frameworks such as kotlinx-serialization, ktor etc
Testing libraries will be JS specific. So instead of mockito / mockk / junit family, you'll need to get familiar with karma / mocha family.
There will be a difference in Coroutine capabilities - both in terms of the way one writes code and performance expectations.
I found reading about Kotlin Multiplatform helped clarify a lot about the capabilities of kotlin.
I know this was not specifically asked, but giving my 2cents to people considering Kotlin/JS (as of Sep'20)
Great if you're familiar with Kotlin and don't foresee too many third party dependencies apart from http i/o (ktor) , React ( kotlin-react) and basic html / css (covered by kotlin-styled).
Using JS modules as dependencies is not as straight forward as using JVM dependencies since there is no ready-made interop. One has to define javascript functions/classes in kotlin before using them (see here). So if you foresee leveraging a lot of existing javascript modules, it won't be an ideal way forward.
Great if you have a typical backend-frontend model where backend compiles to JVM and Frontend compiles to JS. You can leverage a common data model and http i/o framework across Backend and Frontend code (via Kotlin Multiplatform). I've found this to be a tremendous productivity boost!
Kotlin/JS compiles Kotlin code, including its own standard library, into Javascript code. At the end, that's all you have is Javascript. What you don't have is any connection to the Java Virtual Machine. Kotlin's standard library provides no magic to bridge Javascript code to the JVM so that it can utilize Java classes. So NO, you can't utilize Java classes in standard Kotlin/JS.

What's the benefits of writing JavaScript code using Kotlin?

While reading Kotlin to JavaScript tutorial, I'm just wondered what's the benefits of writing JavaScript code using Kotlin?
Beside,
there are already great tools for Javascript developing, like package-manager, Webpack, Gulp...
The benefit is similar to using javascript for server and client. A common language with shared code.
Kotlin can be used for server and client, and aspects of code can be shared. Can use JVM for back-end, and JS tools/frameworks for front-end.
I'm not necessarily recommending this approach, but can see value in it. If you already know Kotlin, it means you don't have to learn JS.
Kotlin is also officially supported for creating Android apps, and Jetbrains are in the process of allowing for development of iOS apps in Kotlin.
So, can use one language across all platforms.