views:

961

answers:

1

I am using following code to start activity when user pressing search button on the handset

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
 if(keyCode == KeyEvent.KEYCODE_SEARCH){
  Util.startActivity(ReviewsDetail.this, KeywordSearch.class);
  return false;
 }else{
  return super.onKeyUp(keyCode, event); 
 }
}

But here are few issues with it please look at the following image.

When press search button it first show google search box at the top of activity then start activity which i want to start

alt text

alt text

When click on the back button displays empty actiivty alt text

+4  A: 

First of all, it is generally not recommended that you override the default behavior of the search button, but if it really makes sense in your case, then there's a special event for that:

 @Override
 public boolean onSearchRequested() {

     // your logic here

     return false;  // don't go ahead and show the search box
 }
David Hedlund
thanks alot it is working.
Faisal khan
i'm glad to hear it. if you're happy with a response, please mark it as 'accepted', by ticking the accept-icon underneath the vote symbols, so that other users can see that this issue has been resolved.
David Hedlund