title: access to search edit text in action bar using appcompat
body: <p>Hi i want to set listener to search edit text in android 2.3 for that i'm using appcompat.<br>
  my contact_menu.xml is    </p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:myapp="http://schemas.android.com/apk/res-auto" &gt;
  
  &lt;item
      android:id="@+id/action_search"
      android:orderInCategory="100"
      android:title="@string/action_search"
      myapp:actionViewClass="android.support.v7.widget.SearchView"
      myapp:showAsAction="always"
      android:actionLayout="@layout/actionbar_search"
      /&gt;
  </code></pre>
  
  <p></p>
  
  <p>my actionbar_search.xml is     </p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="right"
      android:orientation="vertical" &gt;
  
      &lt;EditText
          android:id="@+id/search"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:ems="10" &gt;
  
          &lt;requestFocus /&gt;
      &lt;/EditText&gt;
  
  &lt;/LinearLayout&gt;    
  </code></pre>
  
  <p>and my code    </p>
  
  <pre><code>@Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.contact_menu, menu);
  
              View v = (View) menu.findItem(R.id.action_search).getActionView();
  
              //** Get the edit text from the action view *
              EditText txtSearch = ( EditText ) v.findViewById(R.id.search);
  
              //** Setting an action listener *
              txtSearch.setOnEditorActionListener(new OnEditorActionListener() {
  
                  @Override
                  public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                      Toast.makeText(getBaseContext(), "Search : " + v.getText(), Toast.LENGTH_SHORT).show();
                      return false;
                  }
              });
  
          return true;
      }
  </code></pre>
  
  <p>problem is when i run it in android 2.3 emulator i'm giving this error message     </p>
  
  <pre><code>     11-17 07:31:05.893: E/AndroidRuntime(625): FATAL EXCEPTION: main
  11-17 07:31:05.893: E/AndroidRuntime(625): java.lang.NoSuchMethodError: android.view.MenuItem.getActionView
  11-17 07:31:05.893: E/AndroidRuntime(625):  at com.rad.sarinab.contacts.onCreateOptionsMenu(contacts.java:172)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at android.app.Activity.onCreatePanelMenu(Activity.java:2158)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:224)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at android.support.v7.app.ActionBarActivityDelegateBase$1.run(ActionBarActivityDelegateBase.java:70)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at android.os.Handler.handleCallback(Handler.java:587)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at android.os.Handler.dispatchMessage(Handler.java:92)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at android.os.Looper.loop(Looper.java:123)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at android.app.ActivityThread.main(ActivityThread.java:3683)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at java.lang.reflect.Method.invokeNative(Native Method)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at java.lang.reflect.Method.invoke(Method.java:507)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  11-17 07:31:05.893: E/AndroidRuntime(625):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p><strong>UPDATE</strong><br>
  after some research and useful comment by @blubrain and of course <a href="http://www.stackoverflow.com/questions/25533235/is-it-possible-to-display-an-edittext-widget-on-the-action-bar-without-inflating">this answer </a> i reach to this code:    </p>
  
  <p>my menu</p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:sarinaB="http://schemas.android.com/apk/res-auto"  &gt;
  
      &lt;item
          android:id="@+id/add_item"
          android:icon="@drawable/add"
          android:orderInCategory="100"
          sarinaB:showAsAction="always"/&gt;
      &lt;item
          android:id="@+id/action_search"
           android:icon="@android:drawable/ic_menu_search"
          sarinaB:actionViewClass="android.support.v7.widget.SearchView"
          android:orderInCategory="100"
          android:title="@string/action_search"
          sarinaB:showAsAction="ifRoom"/&gt;
  
  &lt;/menu&gt;
  </code></pre>
  
  <p>my oncreateoptionmenu </p>
  
  <pre><code>@Override
      public boolean onCreateOptionsMenu(Menu menu) { 
          getMenuInflater().inflate(R.menu.contact_menu, menu); 
          MenuItem searchItem = menu.findItem(R.id.action_search); 
          SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
  
          searchView.setOnQueryTextListener(new OnQueryTextListener() {
  
              @Override
              public boolean onQueryTextSubmit(String text) {
                  Toast.makeText(getApplicationContext(), "dddddd "+text, Toast.LENGTH_LONG).show();
                  return false;
              }
  
              @Override
              public boolean onQueryTextChange(String text) {
                  Toast.makeText(getApplicationContext(), "sssssss "+text, Toast.LENGTH_LONG).show();
                  return false;
              }
          });
  
  
      return true;
      }
  </code></pre>