Why after setOnTouchListener does not work the other (Android)












0















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 ?










share|improve this question




















  • 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
















0















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 ?










share|improve this question




















  • 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














0












0








0








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 ?










share|improve this question
















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 android android-studio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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"..? 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














  • 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








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












2 Answers
2






active

oldest

votes


















1














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.






share|improve this answer



















  • 1





    I understood thanks for the help .

    – vinom
    Nov 20 '18 at 12:03



















0














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().






share|improve this answer
























  • I understood thanks for the help .

    – vinom
    Nov 20 '18 at 12:03











  • Vote up please ?

    – Taha wakeel
    Nov 20 '18 at 12:04











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
});


}
});














draft saved

draft discarded


















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









1














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.






share|improve this answer



















  • 1





    I understood thanks for the help .

    – vinom
    Nov 20 '18 at 12:03
















1














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.






share|improve this answer



















  • 1





    I understood thanks for the help .

    – vinom
    Nov 20 '18 at 12:03














1












1








1







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 11:27









JujinkoJujinko

198211




198211








  • 1





    I understood thanks for the help .

    – vinom
    Nov 20 '18 at 12:03














  • 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













0














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().






share|improve this answer
























  • I understood thanks for the help .

    – vinom
    Nov 20 '18 at 12:03











  • Vote up please ?

    – Taha wakeel
    Nov 20 '18 at 12:04
















0














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().






share|improve this answer
























  • I understood thanks for the help .

    – vinom
    Nov 20 '18 at 12:03











  • Vote up please ?

    – Taha wakeel
    Nov 20 '18 at 12:04














0












0








0







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().






share|improve this answer













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().







share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word