Elnaz
Elnaz

Reputation: 1093

android widget SearchView OnQueryTextListener

I want to implement search method for android in android Scala eclipse plug in:

I have this method :

val queryListener = new OnQueryTextListener() {

override def onQueryTextChange(newText: String): Boolean = {
  if (TextUtils.isEmpty(newText)) {
    getActivity.getActionBar.setSubtitle("List")
    val grid_currentQuery = null
  } else {
    getActivity.getActionBar.setSubtitle("List - Searching for: " + newText)
    val grid_currentQuery = newText
  }
  getLoaderManager.restartLoader(0, null, this)

  false
}

in this line " getLoaderManager.restartLoader(0, null, this)" I have an error for "this", My error is:

 type mismatch; found : android.widget.SearchView.OnQueryTextListener required: 
  android.support.v4.app.LoaderManager.LoaderCallbacks[?]

Would you please help me in this implementation

Thanks in advance!

Update 1 :

I used it before but still an error

 getLoaderManager.restartLoader(0, null, BooksFragment.this)

My Error is :

 Multiple markers at this line
- type mismatch; found : com.android.BooksFragment required: 
 android.support.v4.app.LoaderManager.LoaderCallbacks[?]
- type mismatch; found : com.android.BooksFragment required: 

Upvotes: 0

Views: 855

Answers (1)

pt2121
pt2121

Reputation: 11870

Your "this" refers to something with a type OnQueryTextListener. It should be a reference of variable with LoaderCallbacks[?] type instead. Try replacing this with a LoaderCallbacks variable.

Maybe getLoaderManager.restartLoader(0, null, yourLoaderClassVariable)

For example, if you follow the official android document, try

getLoaderManager.restartLoader(0, null, CursorLoaderListFragment.this)

Update:

class CursorLoaderListFragment extends ListFragment with OnQueryTextListener with OnCloseListener with LoaderManager.LoaderCallbacks[Cursor] {
...
    def onQueryTextChange(newText: String): Boolean = {
    ...
        getLoaderManager.restartLoader(0, null, CursorLoaderListFragment.this)
    ...
    true
    }
}

In your case, it might look like this:

class BooksFragment extends ListFragment with OnQueryTextListener with OnCloseListener with LoaderManager.LoaderCallbacks[Cursor]

Update 2: For the second error, try add these three lines. You can implement them later.

def onLoadFinished(l: Loader[Cursor], c: Cursor): Unit = ??? 
def onLoaderReset(l: Loader[Cursor]): Unit = ??? 
def onQueryTextChange(s: String): Boolean = ???

Upvotes: 1

Related Questions