Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

SearchView as ActionView not working (Android Action Bar)

$
0
0

I'm attempting to utilize a SearchView inside the action bar with Android, and having some trouble with getting things working. I've copied the code samples directly from the docs and still no dice.

Here's what's going on:

index.xml

<Alloy>
    <Window id="index" class="container">
        <Label id="label">Search Bar Test</Label>
    </Window>
</Alloy>

index.js

var win = $.index;
var search;
var searchAsChild = false;
 
if (Ti.Platform.name == 'android' && Ti.Platform.Android.API_LEVEL >= 11) {
    // Use action bar search view
    search = Ti.UI.Android.createSearchView({
        hintText : "Table Search"
    });
 
    win.activity.onCreateOptionsMenu = function(e) {
        var menu = e.menu;
        var menuItem = menu.add({
            title : 'Table Search',
            actionView : search,
            icon : Ti.Android.R.drawable.ic_menu_search,
            showAsAction : Ti.Android.SHOW_AS_ACTION_IF_ROOM | Ti.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
        });
    };
}
 
$.index.open();
This successfully displays the search icon, but pressing the icon doesn't invoke the SearchView in the ActionBar. Does anything here look incorrect?

Just FYI - I'm targeting SDK version 17, so I'm well in the clear on that requirement.

Thanks so much,

Justin Davis


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>