Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio/IntelliJ - Field/Variable/Constant creation shortcut

Trying to go from eclipse where you can go over some text, do ctrl-1, select something like create/extract constant, and then it will automatically create it.

The equivalent is roughly ctrl-shift-alt-T, then select from the listing.

Unfortunately in Android Studio, I keep getting:

"cannot perform refactoring. unknown expression type."

Is there any way around this?

What confuses me is that the little lightbulb pops up, and I can click on that, and create constant through there works (and it knows the correct type, etc.).
An alternative acceptable answer would be how to automatically select the little lightbulb that pops up with a keyboard shortcut

like image 874
CasualT Avatar asked Feb 14 '15 00:02

CasualT


People also ask

What is the IntelliJ shortcut to create a local variable?

What is the IntelliJ shortcut to create a local variable? If you cursor is on the line and you hit CTRL + 1 you get a context menu to 'assign a new local variable', resulting in the following: Can you do this as easily in IntelliJ? I've search the net but without success. In Eclipse, it's faster to do "Ctrl-2 l" (lower-case L). Yep!

How do I replace a variable with a constant in IntelliJ?

In the editor, select an expression or declaration of a variable you want to replace with a constant. Press Ctrl+Alt+C to introduce a constant or select Refactor | Extract | Constant. By default, IntelliJ IDEA uses the in-place refactoring.

What are the Android Studio configuration variables?

The Android Studio configuration variables contain settings that customize the location of configuration files and the JDK. On start-up, Android Studio checks these variables for settings.

Can you assign a new variable in IntelliJ using the cursor?

If you cursor is on the line and you hit CTRL + 1 you get a context menu to 'assign a new local variable', resulting in the following: Can you do this as easily in IntelliJ? I've search the net but without success. In Eclipse, it's faster to do "Ctrl-2 l" (lower-case L). Yep! This is the Introduce Variable refactoring.


2 Answers

Select the String that need to be converted into the constant use CTRL + ALT + C (on Windows) or Cmd + ALT + C (on Mac OS)
For more details I think the flowing link gonna help you Extract Constant

like image 188
Faisal Mohammad Avatar answered Oct 13 '22 16:10

Faisal Mohammad


Select the String that need to be converted into the constant use CTRL + ALT + C (on Windows) or Cmd + ALT + C (on Mac OS) For more details I think the flowing link gonna help you Extract Constant

like image 31
Parveen Akter Avatar answered Oct 13 '22 15:10

Parveen Akter