1

Can anyone please help in how to add a button to the expanded SearchView (placed in ActionBar) below the list of recent search suggestions the SearchView is showing?

Since SearchView extends LinearLayout, I have tried to add a button in the layout, but I am not able to place it below the expanded suggestions list.

I made a vertical linearlayout called 'mysearch' with a SearchView and a button below it. Then I also referred to it in android:actionLayout="@layout/mysearch" inmenu.xml` for ActionBar.

I try to get a reference to SearchView in onCreateOptionsMenu of my activity by using

  SearchView searchView = 
      (SearchView)menu.findItem(R.id.menu_search).getActionView();

When I run it, I get a ClassCastException:cannot convert LinearLayout to SearchView, maybe because getActionView() is expecting SearchView but here a LinearLayout it being returned. I dont know how to work around this.

Akhil
  • 13,888
  • 7
  • 35
  • 39

1 Answers1

0

You should be able to put a SearchView into a vertical LinearLayout and simply add the button below it.

DonGru
  • 13,532
  • 8
  • 45
  • 55
Joru
  • 4,406
  • 1
  • 19
  • 13
  • I tried to do that and use a layout in actionLayout attribute , but still not able to do it. I have put the details in the rephrased question above.Please help – Akhil Aug 31 '11 at 17:04