1


I want to add SearchView to another View. I can't place it to ActionBar(I hide native actionBar and create custom view instead).
When I add it to View and set search:searchBar to TableView, my app crashes.
I use Appcelerator Studio, platform is Android

Here is the code I use:

var searchBar = Ti.UI.createSearchBar({
    hintText:"",  
    color:"#000000",  
    barColor:"#eaeaea",  
    height:40,  
    borderColor:"#ffffff",  
    backgroundColor:"#ffffff",  
    showCancel:false  
}); 
var prevadzkyListView = Ti.UI.createListView({
top:55, 
templates:{'simple':cTemplate},
separatorStyle:1,
width:width,
height:height-80,
backgroundColor: 'transparent',
editing: false,
moving: false,
visible: true,
scrollable:true,
searchView:searchBar,
resultsBackgroundColor: "#c0392b",

});

  • Please provide required code where the app crashes and how you are creating and setting the searchbar/view to table's search property. – Prashant Saini Sep 15 '16 at 04:09

1 Answers1

0

Add below in your Layout XML:

   <SearchView
            android:id="@+id/searchView"
            android:layout_width="match_parent"
            android:elevation="2dp"
            android:background="#fff"
            android:layout_height="wrap_content"> 
        </SearchView>

Add below in your java activity class:

searchView = (SearchView) findViewById(R.id.searchView);
        searchView.setQueryHint("Search View");   
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                Toast.makeText(getBaseContext(), query, Toast.LENGTH_LONG).show();
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                Toast.makeText(getBaseContext(), newText, Toast.LENGTH_LONG).show();
                return false;
            }
        });

Note: import android.widget.SearchView;

Chandrahasan
  • 1,991
  • 24
  • 26