how can i make one button do two things

Put your problem here if it does not fit any of the other categories.

how can i make one button do two things

Postby manutd » Mon Oct 26, 2009 10:53 pm

Hi

I need help with a camera application im creating.

Basically I want to take a photo, then automatically move to the next class just by pressing one button.

I have the code for the camera aspect working perfect, preview, layout, button to take photo and save locally. Just need help to move class automatically once the button has been pressed to take the photo.
manutd
Freshman
Freshman
 
Posts: 2
Joined: Mon Oct 26, 2009 10:42 pm

Top

Postby padde » Tue Oct 27, 2009 12:36 am

For multiple functions....
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.     Button bt = new Button(this);
  3.  
  4.  
  5.  
  6.     bt.setOnClickListener(new View.OnClickListener() {
  7.  
  8.         public void onClick(View v) {
  9.  
  10.             int count = (v.getTag() != null) ? (Integer) v.getTag() : 0;
  11.  
  12.                 switch(count) {
  13.  
  14.                     case 0:
  15.  
  16.                         Log.v("Button", "do something");
  17.  
  18.                         count++;
  19.  
  20.                         break;
  21.  
  22.                     case 1:
  23.  
  24.                         Log.v("Button", "do something else");
  25.  
  26.                         count++;
  27.  
  28.                         break;
  29.  
  30.                     case 2:
  31.  
  32.                         Log.v("Button", "do something different");
  33.  
  34.                         count = 0;
  35.  
  36.                         break;
  37.  
  38.                 }
  39.  
  40.                 v.setTag(count);
  41.  
  42.             }
  43.  
  44.         });
  45.  
  46.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Or in your case for two functions...
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.     Button bt = new Button(this);
  3.  
  4.  
  5.  
  6.     bt.setOnClickListener(new View.OnClickListener() {
  7.  
  8.         public void onClick(View v) {
  9.  
  10.             if(v.getTag() == null) {  
  11.  
  12.                 Log.v("Button", "do 1");
  13.  
  14.                 v.setTag(true);
  15.  
  16.             } else {
  17.  
  18.                 Log.v("Button", "do 2");
  19.  
  20.                 v.setTag(null);
  21.  
  22.             }
  23.  
  24.         }
  25.  
  26.     });
  27.  
  28.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby manutd » Thu Oct 29, 2009 3:00 pm

Thank you, Works great :D
manutd
Freshman
Freshman
 
Posts: 2
Joined: Mon Oct 26, 2009 10:42 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 13 guests