problem With Home Back screen button

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

problem With Home Back screen button

Postby bins1984 » Thu Mar 13, 2008 6:09 am

hi ....i was trying to implement home button and back to screen button for my application ,On key listener i give the key code of the home ..but when ever i click on the button just blink the screen and going back to home screen....and same thing happening in the back screen button also.....

the key are not supporting by android or is that possible to implement the home and back keys????


if any body come across with the problem please help me.........

with thanks
binis
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Top

Postby cabernet1976 » Thu Mar 13, 2008 7:37 am

Hi bins1984,

Why not to paste your code :?:
I think it will help people to duplicate your issue :)
Upload2Flickr's blog: http://upload2flickr.blogspot.com
cabernet1976
Senior Developer
Senior Developer
 
Posts: 154
Joined: Fri Nov 16, 2007 2:34 am
Location: China

Postby bins1984 » Thu Mar 13, 2008 4:51 pm

hi....this is the code i was trying....can any body can u help me..



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class buttons extends Activity {
  2.  
  3.     /** Called when the activity is first created. */
  4.  
  5.     @Override
  6.  
  7.     public void onCreate(Bundle icicle) {
  8.  
  9.         super.onCreate(icicle);
  10.  
  11.         setContentView(R.layout.main);
  12.  
  13.        final TextView mtext=(TextView)findViewById(R.id.text1);
  14.  
  15.        Button mbutton=(Button)findViewById(R.id.button1);
  16.  
  17.        Button mbutton1=(Button)findViewById(R.id.button2);
  18.  
  19.        
  20.  
  21.        mbutton.setOnKeyListener(new OnKeyListener() {
  22.  
  23.  
  24.  
  25.                         public boolean onKey(View v, int keyCode, KeyEvent event) {
  26.  
  27.                                 if (keyCode==KeyEvent.KEYCODE_HOME) {
  28.  
  29.                                        
  30.  
  31.                                         mtext.setText("Home key is working");
  32.  
  33.                                         return true;
  34.  
  35.                                         }
  36.  
  37.                                
  38.  
  39.                                 return false;
  40.  
  41.                                      
  42.  
  43.                                         }
  44.  
  45.                                    });
  46.  
  47.        
  48.  
  49.        mbutton1.setOnKeyListener(new OnKeyListener() {
  50.  
  51.  
  52.  
  53.                         public boolean onKey(View v, int keyCode, KeyEvent event) {
  54.  
  55.                                 if (keyCode==KeyEvent.KEYCODE_BACK) {
  56.  
  57.                                        
  58.  
  59.                                         mtext.setText("key is working");
  60.  
  61.                                         return true;
  62.  
  63.                                         }
  64.  
  65.                                
  66.  
  67.                                 return false;
  68.  
  69.                                      
  70.  
  71.                                         }
  72.  
  73.                                    });
  74.  
  75.        
  76.  
  77.                                
Parsed in 0.035 seconds, using GeSHi 1.0.8.4





please if anybbody can help mee.....or can any body can currect my code....
still its not working..... :cry:




thanks.....
bins
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

hmmm

Postby cadlg » Thu Mar 13, 2008 5:26 pm

Hi bins.

I'm not sure I understand what you are trying to do, but if you want your buttons to do something when you click on them, you should set "OnClickListener", not OnKeyListener.

At the other hand, if you want your view to do something when a key is pressed, then I guess you don't need to use buttons...

Regards,

cadlg
cadlg
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Wed Feb 20, 2008 12:33 am
Location: Guatemala

Postby bins1984 » Thu Mar 13, 2008 6:35 pm

hi cadlg
wht u mean i understood.....but in other keys KeyCode are working with the button........
u just try the code i had pasted and insted of the KEYCODE_HOME give some other key code..
that will work.....but why KEYCODE_HOME is not working????????????
is it not pssible do in this way?????
if anybody know other solution please give replay......

thanks
bins
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 20 guests