0

I'm trying to use EditText instead of SearchView in this Code

  private void setupSearchView() {
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) findViewById(R.id.searchView);
    SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
    searchView.setSearchableInfo(searchableInfo);
}

and my layout that I want to use is

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SearchViewActivity" >


<EditText android:id="@+id/searchViewET"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"/>

<TextView
    android:id="@+id/searchViewResult"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/searchView"
    android:layout_centerHorizontal="true"
    android:text="@string/hello_world" />

</RelativeLayout>

Thats because I'm using low api level (level 8) and SearchView make my App crashed. How to do that? Thanks in Advance.

Eman87
  • 2,735
  • 7
  • 36
  • 53
  • Use a RealtiveLayout and place EditText at the top – Raghunandan Jan 11 '14 at 19:00
  • I added my layout in post aupdate, I can't configure the code in `setupSearchView()` method, could you help me by sample code, please. – Eman87 Jan 11 '14 at 19:07
  • You have two options : 1. use `SearchViewCompat` from compat library. 2. use `EditText` and implement your own search logic. If that is what you want check this answer http://stackoverflow.com/a/6529953/2358786 – kiruwka Jan 11 '14 at 22:09
  • look to this example http://looksok.wordpress.com/2013/06/15/android-searchview-tutorial-edittext-with-phone-contacts-search-and-autosuggestion/ all what I want to do is to replace SearchView with EditText, what is the logic of the editText in method `setupSearchView()` this is all what I want to know. – Eman87 Jan 11 '14 at 22:34

2 Answers2

3

in xml you use edittext while in program you use searchview ?? I dont get what the problem exactly with your code if you use edittext as a search then you should also get view of edittext and then set it onTextChangeListener() of edittext to search the item

Ahmad Joyia
  • 533
  • 5
  • 17
  • I want to integrate the `setupSearchView()` method to use editText instead of SearchView and I don't know how to do this. Meaning that the SearchView causes my app to crash bec. of api level and I want to replace it with edittext in the function itself not in layout. – Eman87 Jan 11 '14 at 19:59
  • 1
    one options is this you dont use searchview for searching you should use edittext and implements onTextchangeListener() for search every alphabit because SearchView is form api level 11 and if you give back end compitibility you dont use SearchView and its method for searching – Ahmad Joyia Jan 12 '14 at 05:32
0

The Android Support Library App Compat Library backports the Action Bar features, including SearchView back to API7+ devices. Then you can add a SearchView per the Action Bar guide and use all the methods you would normally use on newer devices.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443