how could i remove ontouchlistener

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

how could i remove ontouchlistener

Postby slashgill » Sun Feb 07, 2010 5:40 am

hi,
I setOnTouchListener() to an AbsoluteLayout.
How could I disable OnTouch() after I touched the AbsoluteLayout 10 times?


this is my code
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                 AbsoluteLayout map_layout = (AbsoluteLayout) findViewById(R.id.map_layout);
  3.  
  4.                 map_layout.setOnTouchListener(this);   
  5.  
  6.  
  7.  
  8.  
  9.  
  10.         public boolean onTouch(View v, MotionEvent event) {
  11.  
  12.                 Toast.makeText(this,"touched", Toast.LENGTH_LONG).show();
  13.  
  14.                 player_times_int = player_times_int + 1;
  15.  
  16.                 if (player_times_int == 10){
  17.  
  18.                     //I want to disable the onTouch, how could I do ??
  19.  
  20.                                 }
  21.  
  22.                 return false;
  23.  
  24.         }
  25.  
  26.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Thanks!
slashgill
Junior Developer
Junior Developer
 
Posts: 16
Joined: Mon Jan 25, 2010 5:14 am

Top

Re: how could i remove ontouchlistener

Postby azraeal » Wed Feb 10, 2010 12:08 am

Instead of focusing on "turning off" the onTouch(), just bypass your logic once the criteria has been met.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public boolean onTouch(View v, MotionEvent event) {
  2.  
  3.                
  4.  
  5.                 player_times_int = player_times_int + 1;
  6.  
  7.                 if (player_times_int <= 10){
  8.  
  9.                    Toast.makeText(this,"touched", Toast.LENGTH_LONG).show();
  10.  
  11.                    //additional actions
  12.  
  13.                 }
  14.  
  15.         return false;
  16.  
  17. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Postby slashgill » Wed Feb 10, 2010 2:17 pm

Thanks, azraeal.

Of course I could code it like yours.
But, if I don't need the onTouch anymore, why not just remove the listener?
I mean that I don't want to waste the OS resource to process additional operation.

Thought?
slashgill
Junior Developer
Junior Developer
 
Posts: 16
Joined: Mon Jan 25, 2010 5:14 am

Postby Rahul » Wed Feb 10, 2010 2:44 pm

In that case try using a property called setenabled to false.

in your case

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. map_layout.setenabled(false);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


after u receive the 10th call

Avoid using AbsoluteLayout since it has been deprecated

slashgill wrote:Thanks, azraeal.

Of course I could code it like yours.
But, if I don't need the onTouch anymore, why not just remove the listener?
I mean that I don't want to waste the OS resource to process additional operation.

Thought?
Rahul
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Wed Oct 01, 2008 11:16 am

Postby slashgill » Mon Feb 15, 2010 5:10 pm

Thanks for your help, Rahul.
slashgill
Junior Developer
Junior Developer
 
Posts: 16
Joined: Mon Jan 25, 2010 5:14 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 9 guests