Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto replace into lambda expressions in Android Studio

I enabled lambda expressions in Android Studio and it works fine, but each time I use shortcuts to write down a new interface it shows in the pre-Java-8 form and not in a lambda expression and I have to manually replace it each time.!

Is there a way to let Android Studio to auto replce ot lambda expression?

see here what I mean =>

enter image description here

like image 611
Alaa AbuZarifa Avatar asked Jan 28 '26 15:01

Alaa AbuZarifa


2 Answers

If you want to replace all the lambda expression from the project you can try Ctrl + Shift+ Alt + I on inspection search tab, search anonymous type can be replaced with lambda. It will replace all the anonymous type to lambda.

like image 198
Nagendra Hari Karthick Avatar answered Jan 30 '26 03:01

Nagendra Hari Karthick


Set compile options and set source and target compatibility to 1.8 in your build.gradle. Now whenever you type the listener simply using ctrl+space will show lambda as option for auto-fill.

enter image description here

like image 39
karan Avatar answered Jan 30 '26 03:01

karan