• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to import the necessary components

robothito

Newbie
Feb 2, 2016
26
3
Hello and thanks always for the help.

Right now I am following a tutorial (om android programming)
So for example, say I type something like this

Code:
private Button mybutton;

it can happen that the class "Button" is not imported so Android Studio marks it with red.
the tutorial says that to correct this I can point there with my cursor and type ALT+ENTER

well, I have a mac, so I tried basically Option +Enter...

it works sometimes..... and sometimes it doesnt. (Once it gave me some new element (GoogleApiClient) added by google or something)

Anyway. First question: How can you correct this so that the necessary import appears above in my code ?
Code:
import android.widget.Button;

Also Second Question and actually very basic and important one!

How do you "undo" things on Android studio. I mean there seems to be a "normal" undo and redo button on the menu but they don't undo things on my code!!! They actually -for example if I am in the java code switch to the XML screen or something like that. I can never "undo" if I say deleted a whole function by accident ot things like that. Any help greatly appreciated
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones