About the Toast command [duplicate]
This question already has an answer here:
what is the activity name in anonymous class
4 answers
I want to know what 'this' means in the below Toast command:
Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();
If possible could you please explain the whole command.
java android
marked as duplicate by Sergey Glotov
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 11:00
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
what is the activity name in anonymous class
4 answers
I want to know what 'this' means in the below Toast command:
Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();
If possible could you please explain the whole command.
java android
marked as duplicate by Sergey Glotov
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 11:00
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Just read: developer.android.com/guide/topics/ui/notifiers/toasts#java . If you do not know what a context is then you need to read some books/tutorials about it first.
– ZUNJAE
Nov 20 at 10:02
Toast
is an object, not a command. You lack the fundamentals of OOP.
– Fantômas
Nov 20 at 10:21
add a comment |
This question already has an answer here:
what is the activity name in anonymous class
4 answers
I want to know what 'this' means in the below Toast command:
Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();
If possible could you please explain the whole command.
java android
This question already has an answer here:
what is the activity name in anonymous class
4 answers
I want to know what 'this' means in the below Toast command:
Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();
If possible could you please explain the whole command.
This question already has an answer here:
what is the activity name in anonymous class
4 answers
java android
java android
edited Nov 20 at 10:57
Sergey Glotov
16.6k117288
16.6k117288
asked Nov 20 at 9:53
Aravind D
12
12
marked as duplicate by Sergey Glotov
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 11:00
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Sergey Glotov
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 11:00
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Just read: developer.android.com/guide/topics/ui/notifiers/toasts#java . If you do not know what a context is then you need to read some books/tutorials about it first.
– ZUNJAE
Nov 20 at 10:02
Toast
is an object, not a command. You lack the fundamentals of OOP.
– Fantômas
Nov 20 at 10:21
add a comment |
Just read: developer.android.com/guide/topics/ui/notifiers/toasts#java . If you do not know what a context is then you need to read some books/tutorials about it first.
– ZUNJAE
Nov 20 at 10:02
Toast
is an object, not a command. You lack the fundamentals of OOP.
– Fantômas
Nov 20 at 10:21
Just read: developer.android.com/guide/topics/ui/notifiers/toasts#java . If you do not know what a context is then you need to read some books/tutorials about it first.
– ZUNJAE
Nov 20 at 10:02
Just read: developer.android.com/guide/topics/ui/notifiers/toasts#java . If you do not know what a context is then you need to read some books/tutorials about it first.
– ZUNJAE
Nov 20 at 10:02
Toast
is an object, not a command. You lack the fundamentals of OOP.– Fantômas
Nov 20 at 10:21
Toast
is an object, not a command. You lack the fundamentals of OOP.– Fantômas
Nov 20 at 10:21
add a comment |
3 Answers
3
active
oldest
votes
In general when you use construct SomeClass.this
that means that you are referring to the specific (frequently 'outer' class). In example you can have a code like:
class Apple {
void outherMethod() {
}
class AppleType {
void innerMethod(){}
void method(){
Apple.this.outerMethod();
this.innerMethod();
}
}
}
Additionally, in this specific case on Android it means that you are using the activity's Context which is provided via MainActivity class.
So the whole command should be read as:
- Create Toast widget inside context provided by MainActivity
- It should display some text: "msg"
- It should be visible for specific time defined by the constant: Toast.Length_long
- finally, via show() method display it on device.
add a comment |
'this' means itself.
Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();
Call the toast method, and the required parameters are 'context', 'toast message' and 'toast duration'.
Finally .show() means make toast to show.
whether "this" means that the mainactivity is contained within itself
– Aravind D
Nov 20 at 10:11
@AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
– eltoryn7
Nov 20 at 10:28
add a comment |
its clear and you can use it like this
Toast toast =Toast.makeText(this, "msg", duration);
toast.show();
this: context
"msg": your message
duration: Toast.LENGTH_SHORT or Toast.LENGTH_LONG
and you can change position by setting gravity
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
this will show toast center screen
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
In general when you use construct SomeClass.this
that means that you are referring to the specific (frequently 'outer' class). In example you can have a code like:
class Apple {
void outherMethod() {
}
class AppleType {
void innerMethod(){}
void method(){
Apple.this.outerMethod();
this.innerMethod();
}
}
}
Additionally, in this specific case on Android it means that you are using the activity's Context which is provided via MainActivity class.
So the whole command should be read as:
- Create Toast widget inside context provided by MainActivity
- It should display some text: "msg"
- It should be visible for specific time defined by the constant: Toast.Length_long
- finally, via show() method display it on device.
add a comment |
In general when you use construct SomeClass.this
that means that you are referring to the specific (frequently 'outer' class). In example you can have a code like:
class Apple {
void outherMethod() {
}
class AppleType {
void innerMethod(){}
void method(){
Apple.this.outerMethod();
this.innerMethod();
}
}
}
Additionally, in this specific case on Android it means that you are using the activity's Context which is provided via MainActivity class.
So the whole command should be read as:
- Create Toast widget inside context provided by MainActivity
- It should display some text: "msg"
- It should be visible for specific time defined by the constant: Toast.Length_long
- finally, via show() method display it on device.
add a comment |
In general when you use construct SomeClass.this
that means that you are referring to the specific (frequently 'outer' class). In example you can have a code like:
class Apple {
void outherMethod() {
}
class AppleType {
void innerMethod(){}
void method(){
Apple.this.outerMethod();
this.innerMethod();
}
}
}
Additionally, in this specific case on Android it means that you are using the activity's Context which is provided via MainActivity class.
So the whole command should be read as:
- Create Toast widget inside context provided by MainActivity
- It should display some text: "msg"
- It should be visible for specific time defined by the constant: Toast.Length_long
- finally, via show() method display it on device.
In general when you use construct SomeClass.this
that means that you are referring to the specific (frequently 'outer' class). In example you can have a code like:
class Apple {
void outherMethod() {
}
class AppleType {
void innerMethod(){}
void method(){
Apple.this.outerMethod();
this.innerMethod();
}
}
}
Additionally, in this specific case on Android it means that you are using the activity's Context which is provided via MainActivity class.
So the whole command should be read as:
- Create Toast widget inside context provided by MainActivity
- It should display some text: "msg"
- It should be visible for specific time defined by the constant: Toast.Length_long
- finally, via show() method display it on device.
answered Nov 20 at 10:13
rsulkowski
263
263
add a comment |
add a comment |
'this' means itself.
Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();
Call the toast method, and the required parameters are 'context', 'toast message' and 'toast duration'.
Finally .show() means make toast to show.
whether "this" means that the mainactivity is contained within itself
– Aravind D
Nov 20 at 10:11
@AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
– eltoryn7
Nov 20 at 10:28
add a comment |
'this' means itself.
Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();
Call the toast method, and the required parameters are 'context', 'toast message' and 'toast duration'.
Finally .show() means make toast to show.
whether "this" means that the mainactivity is contained within itself
– Aravind D
Nov 20 at 10:11
@AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
– eltoryn7
Nov 20 at 10:28
add a comment |
'this' means itself.
Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();
Call the toast method, and the required parameters are 'context', 'toast message' and 'toast duration'.
Finally .show() means make toast to show.
'this' means itself.
Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();
Call the toast method, and the required parameters are 'context', 'toast message' and 'toast duration'.
Finally .show() means make toast to show.
answered Nov 20 at 10:05
eltoryn7
686
686
whether "this" means that the mainactivity is contained within itself
– Aravind D
Nov 20 at 10:11
@AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
– eltoryn7
Nov 20 at 10:28
add a comment |
whether "this" means that the mainactivity is contained within itself
– Aravind D
Nov 20 at 10:11
@AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
– eltoryn7
Nov 20 at 10:28
whether "this" means that the mainactivity is contained within itself
– Aravind D
Nov 20 at 10:11
whether "this" means that the mainactivity is contained within itself
– Aravind D
Nov 20 at 10:11
@AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
– eltoryn7
Nov 20 at 10:28
@AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
– eltoryn7
Nov 20 at 10:28
add a comment |
its clear and you can use it like this
Toast toast =Toast.makeText(this, "msg", duration);
toast.show();
this: context
"msg": your message
duration: Toast.LENGTH_SHORT or Toast.LENGTH_LONG
and you can change position by setting gravity
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
this will show toast center screen
add a comment |
its clear and you can use it like this
Toast toast =Toast.makeText(this, "msg", duration);
toast.show();
this: context
"msg": your message
duration: Toast.LENGTH_SHORT or Toast.LENGTH_LONG
and you can change position by setting gravity
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
this will show toast center screen
add a comment |
its clear and you can use it like this
Toast toast =Toast.makeText(this, "msg", duration);
toast.show();
this: context
"msg": your message
duration: Toast.LENGTH_SHORT or Toast.LENGTH_LONG
and you can change position by setting gravity
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
this will show toast center screen
its clear and you can use it like this
Toast toast =Toast.makeText(this, "msg", duration);
toast.show();
this: context
"msg": your message
duration: Toast.LENGTH_SHORT or Toast.LENGTH_LONG
and you can change position by setting gravity
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
this will show toast center screen
answered Nov 20 at 10:26
New Developer
762
762
add a comment |
add a comment |
Just read: developer.android.com/guide/topics/ui/notifiers/toasts#java . If you do not know what a context is then you need to read some books/tutorials about it first.
– ZUNJAE
Nov 20 at 10:02
Toast
is an object, not a command. You lack the fundamentals of OOP.– Fantômas
Nov 20 at 10:21