开发者

How to add a Button (like 'Clear History') below the expanded SearchView (showing 10 recent searches) in Android?

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜