gpt4 book ai didi

java - android 小部件 SearchView OnQueryTextListener

转载 作者:行者123 更新时间:2023-12-01 14:12:30 29 4
gpt4 key购买 nike

我想在android Scala eclipse插件中实现android的搜索方法:

我有这个方法:

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
}

在这一行“getLoaderManager.restartLoader(0, null, this)”中,我有一个“this”错误,我的错误是:

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

请您帮助我完成此实现

提前致谢!

更新1:

我以前用过,但还是报错

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

我的错误是:

 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:

最佳答案

您的“this”指的是 OnQueryTextListener 类型的内容。它应该是 LoaderCallbacks[?] 类型的变量的引用。尝试用 LoaderCallbacks 变量替换它。

也许 getLoaderManager.restartLoader(0, null, yourLoaderClassVariable)

例如,如果您关注the official android document ,尝试一下

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

更新:

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

就您而言,它可能如下所示:

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

更新2:对于第二个错误,尝试添加这三行。您可以稍后实现它们。

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

关于java - android 小部件 SearchView OnQueryTextListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18387240/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com