Why after setOnTouchListener does not work the other (Android)
Why the orders after setOnTouchListener do not work ?
For example :
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {
public RelativeLayout MYLL=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MYLL=(RelativeLayout) findViewById(R.id.MYL);
Toast.makeText(getApplicationContext(), "Begin", Toast.LENGTH_SHORT).show();
MYLL.setOnTouchListener(this);
Toast.makeText(getApplicationContext(), "End", Toast.LENGTH_SHORT).show();
}
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(getApplicationContext(), "In", Toast.LENGTH_SHORT).show();
return false;//or true
}
}
When activated setOnTouchListener View a message "In"
But why after the message "In" does not following the other message "End"(In -> End) why ?
java
add a comment |
Why the orders after setOnTouchListener do not work ?
For example :
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {
public RelativeLayout MYLL=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MYLL=(RelativeLayout) findViewById(R.id.MYL);
Toast.makeText(getApplicationContext(), "Begin", Toast.LENGTH_SHORT).show();
MYLL.setOnTouchListener(this);
Toast.makeText(getApplicationContext(), "End", Toast.LENGTH_SHORT).show();
}
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(getApplicationContext(), "In", Toast.LENGTH_SHORT).show();
return false;//or true
}
}
When activated setOnTouchListener View a message "In"
But why after the message "In" does not following the other message "End"(In -> End) why ?
java
3
Why would you get an "End" toast after "In"..?onTouchis called when a touch event occurs, which can happen at any time, e.g. long after execution ofonCreatehas finished.
– Michael
Nov 20 '18 at 11:21
add a comment |
Why the orders after setOnTouchListener do not work ?
For example :
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {
public RelativeLayout MYLL=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MYLL=(RelativeLayout) findViewById(R.id.MYL);
Toast.makeText(getApplicationContext(), "Begin", Toast.LENGTH_SHORT).show();
MYLL.setOnTouchListener(this);
Toast.makeText(getApplicationContext(), "End", Toast.LENGTH_SHORT).show();
}
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(getApplicationContext(), "In", Toast.LENGTH_SHORT).show();
return false;//or true
}
}
When activated setOnTouchListener View a message "In"
But why after the message "In" does not following the other message "End"(In -> End) why ?
java
Why the orders after setOnTouchListener do not work ?
For example :
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {
public RelativeLayout MYLL=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MYLL=(RelativeLayout) findViewById(R.id.MYL);
Toast.makeText(getApplicationContext(), "Begin", Toast.LENGTH_SHORT).show();
MYLL.setOnTouchListener(this);
Toast.makeText(getApplicationContext(), "End", Toast.LENGTH_SHORT).show();
}
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(getApplicationContext(), "In", Toast.LENGTH_SHORT).show();
return false;//or true
}
}
When activated setOnTouchListener View a message "In"
But why after the message "In" does not following the other message "End"(In -> End) why ?
java
java
edited Nov 20 '18 at 12:53
Dávid Horváth
2,30911326
2,30911326
asked Nov 20 '18 at 11:17
vinomvinom
123
123
3
Why would you get an "End" toast after "In"..?onTouchis called when a touch event occurs, which can happen at any time, e.g. long after execution ofonCreatehas finished.
– Michael
Nov 20 '18 at 11:21
add a comment |
3
Why would you get an "End" toast after "In"..?onTouchis called when a touch event occurs, which can happen at any time, e.g. long after execution ofonCreatehas finished.
– Michael
Nov 20 '18 at 11:21
3
3
Why would you get an "End" toast after "In"..?
onTouch is called when a touch event occurs, which can happen at any time, e.g. long after execution of onCreate has finished.– Michael
Nov 20 '18 at 11:21
Why would you get an "End" toast after "In"..?
onTouch is called when a touch event occurs, which can happen at any time, e.g. long after execution of onCreate has finished.– Michael
Nov 20 '18 at 11:21
add a comment |
2 Answers
2
active
oldest
votes
OnCreate is called once in the beginning of your example.
Showing the Toast "Begin", setting the OnTouchListener and then showing the Toast "End".
The OnTouchListener is called on every Touch after being set, NOT when it is first set.
If you wanted the "End" Toast to be called after the "In" Toast, you would need to show the Toast from inside the OnTouchListener after the "In" Toast.
1
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
add a comment |
End will be shown only once when the activity is created not every time but In will be shown up as many time as you touch that view, If you want to show end every time when In shows up put that toast right after In, other wise End will be shown up only once i.e onCreate().
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
Vote up please ?
– Taha wakeel
Nov 20 '18 at 12:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391845%2fwhy-after-setontouchlistener-does-not-work-the-other-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
OnCreate is called once in the beginning of your example.
Showing the Toast "Begin", setting the OnTouchListener and then showing the Toast "End".
The OnTouchListener is called on every Touch after being set, NOT when it is first set.
If you wanted the "End" Toast to be called after the "In" Toast, you would need to show the Toast from inside the OnTouchListener after the "In" Toast.
1
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
add a comment |
OnCreate is called once in the beginning of your example.
Showing the Toast "Begin", setting the OnTouchListener and then showing the Toast "End".
The OnTouchListener is called on every Touch after being set, NOT when it is first set.
If you wanted the "End" Toast to be called after the "In" Toast, you would need to show the Toast from inside the OnTouchListener after the "In" Toast.
1
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
add a comment |
OnCreate is called once in the beginning of your example.
Showing the Toast "Begin", setting the OnTouchListener and then showing the Toast "End".
The OnTouchListener is called on every Touch after being set, NOT when it is first set.
If you wanted the "End" Toast to be called after the "In" Toast, you would need to show the Toast from inside the OnTouchListener after the "In" Toast.
OnCreate is called once in the beginning of your example.
Showing the Toast "Begin", setting the OnTouchListener and then showing the Toast "End".
The OnTouchListener is called on every Touch after being set, NOT when it is first set.
If you wanted the "End" Toast to be called after the "In" Toast, you would need to show the Toast from inside the OnTouchListener after the "In" Toast.
answered Nov 20 '18 at 11:27
JujinkoJujinko
198211
198211
1
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
add a comment |
1
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
1
1
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
add a comment |
End will be shown only once when the activity is created not every time but In will be shown up as many time as you touch that view, If you want to show end every time when In shows up put that toast right after In, other wise End will be shown up only once i.e onCreate().
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
Vote up please ?
– Taha wakeel
Nov 20 '18 at 12:04
add a comment |
End will be shown only once when the activity is created not every time but In will be shown up as many time as you touch that view, If you want to show end every time when In shows up put that toast right after In, other wise End will be shown up only once i.e onCreate().
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
Vote up please ?
– Taha wakeel
Nov 20 '18 at 12:04
add a comment |
End will be shown only once when the activity is created not every time but In will be shown up as many time as you touch that view, If you want to show end every time when In shows up put that toast right after In, other wise End will be shown up only once i.e onCreate().
End will be shown only once when the activity is created not every time but In will be shown up as many time as you touch that view, If you want to show end every time when In shows up put that toast right after In, other wise End will be shown up only once i.e onCreate().
answered Nov 20 '18 at 11:40
Taha wakeelTaha wakeel
896
896
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
Vote up please ?
– Taha wakeel
Nov 20 '18 at 12:04
add a comment |
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
Vote up please ?
– Taha wakeel
Nov 20 '18 at 12:04
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
I understood thanks for the help .
– vinom
Nov 20 '18 at 12:03
Vote up please ?
– Taha wakeel
Nov 20 '18 at 12:04
Vote up please ?
– Taha wakeel
Nov 20 '18 at 12:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391845%2fwhy-after-setontouchlistener-does-not-work-the-other-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Why would you get an "End" toast after "In"..?
onTouchis called when a touch event occurs, which can happen at any time, e.g. long after execution ofonCreatehas finished.– Michael
Nov 20 '18 at 11:21