android - Setting Up the Search Interface

*Add the Search View to the App Bar

*Create a Searchable Activity
-SearchView tries to start an activity with the ACTION_SEARCH when a user submit a search query

* if you run your app now, the SearchView can accept the user's query and start  your searchable activity with the ACTION_SEARCH intent.

*SearchView.OnQueryTextListener - interface
-----------------------------------------------------------------------------------------------------------------------
*Createing a Search Interface
-The Basics:
#search dialog
#search widget is an instance of SearchView

#when the user executes a search from the search dialog or a search widget,
the system creates an Intent and stores the user query in it.

#what you need:
##A Searchable Configuration:
xml file that configures some settings for the search dialog or widget.
it includes settings for features such as void search, search suggestion, and hint text

##A Searchable Activity:
the activity that receives the search query, searches your data,..

##A Search Interface, provided by either:
###The search dialog: usually hidden, but appears when you call onSearchRequested()(press search button)

*Creating a Searchable Configuration file:
xml file(usually searchable.xml):must include <searchable> elements
location:res/xml
The system uses this file to instantiate a SearchableInfo object

*Creating a Searchable Activity
*Declaring a Searchable Activity

*Performing a search in Searchable Activity

*Using the Search Dialog
when the user executes a search, the system sends the search query to a searchable activity
#todo
##indicate to the system which searchable activity should receive search queries from the search dialog
*Invoking the search dialog
.
.
.


--------------------------------------------------------------------------------------------------------------------
*Adding Custom Suggestions
참고: https://mobikul.com/android-inflating-search-suggestions-from-network/

----------------------------------------------------------------------
2018.2.20
<activity    android:name=".SearchResultActivity"    android:launchMode="singleTop">
    <intent-filter>
        <action android:name="android.intent.action.SEARCH"/>
    </intent-filter>
    <meta-data        android:name="android.app.searchable"        android:resource="@xml/searchable"/>
</activity>
이게 있어야 무조건 searchView에서 search가 실행된다.
 

*<activity android:name=".SetMemo" android:launchMode="singleTop">
    <intent-filter>
        <action android:name="android.intent.action.SEARCH"/>
    </intent-filter>
    <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
</activity>

위의 것을 실행하면 searchView에서 text를 입력하다가 에러 발생:
android.database.StaleDataException: Attempting to access a closed CursorWindow.Most probable cause: cursor is deactivated prior to calling this method.

에러가 발생하지 않아도 맨처음 text를 입력하면 나오던suggestion도 보이지 않음.
SearchView자체가 제대로 활성화되지 않은 것이 원인인 듯 하다.

->원인파악ㅇㅇ..
<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <meta-data        android:name="android.app.default_searchable"        android:value=".SearchResultActivity"/>   <- .SetMemo로 고치지 않고 실행함
 
------------------------------------------------------------------------------------------------------------
 




댓글

이 블로그의 인기 게시물

포트란?

안드로이드 스마트폰 연결