简体   繁体   中英

where do I define entity “context” ( unknown entity “Context” ) -using AIDE

I'm very new to java so you have use pictures and small words :)
Anyway I've decided to learn write for Android straight off the bat. I'm using AIDE so my errors are from there not eclipse.

First of all I'm struggling to understand why examples are written as below:

CharSequence text = "Hello toast!"; 
int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration); 
toast.show();

It really make it hard to work out if the last line of code is referencing toast, toast or toast?

Secondly I've pasted the example code into my project and getting the error:

unknown entity "Context" 

I think I need to import something? I've searched but can't find it.

The toast is an instance of an object that shows a very temporary popup message on the screen.

The "context" is something you need to fill, which may be the current activity or anything that extends from the class Context. see here for the full description of the makeToast function.

usually it's inside an activity, so you might use:

class MainActivity {

...onCreate(...) {
...
Toast toast = Toast.makeText(MainActivity.this, text, duration); 
toast.show();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM