gpt4 book ai didi

android - setSuggestionAdapter cursor - 需要更新它

转载 作者:行者123 更新时间:2023-11-30 03:00:39 24 4
gpt4 key购买 nike

所以,我有这两行:

@Override
public boolean onCreateOptionsMenu(Menu menu) {

super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.menu.onime_main, menu);

// Create the search view
SearchView searchView = new SearchView(getSupportActionBar()
.getThemedContext());
searchView.setQueryHint("Search for anime");
searchView.setOnQueryTextListener(this);
searchView.setOnSuggestionListener(this);

if (mSuggestionsAdapter == null) {
cursor = new MatrixCursor(COLUMNS);

cursor.addRow(new String[] { "1", "'Murica" });

mSuggestionsAdapter = new SuggestionsAdapter(getSupportActionBar()
.getThemedContext(), cursor);
}

searchView.setSuggestionsAdapter(mSuggestionsAdapter);

menu.add("Search")
.setIcon(R.drawable.abs__ic_search)
.setActionView(searchView)
.setShowAsAction(
MenuItem.SHOW_AS_ACTION_IF_ROOM
| MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

return true;
}

然后我还有其他功能:

@Override
public boolean onQueryTextChange(String newText) {
// TODO Auto-generated method stub

Log.e("test: ", newText);

List<Serial> temp = db.getSuggestion(newText);

MatrixCursor tempCur = new MatrixCursor(COLUMNS);

for (Serial cn : temp) {
tempCur.addRow(new String[] { cn.getID() + "", cn.getName() });
Log.e("Info:", cn.getID() + " " + cn.getName());
}

cursor = tempCur;

for (Serial cn : temp) {
String log = "Id: " + cn.getID() + " ,Name: " + cn.getName()
+ " ,Description: " + cn.getDescription();
// Writing Contacts to log
Log.d("Name: ", log);
}

mSuggestionsAdapter.notifyDataSetChanged();

return false;
}

想法很简单。我有“搜索框”,无论我输入什么都会有新文本。随之将发送 sql 查询,我从中获取所需的数据(用于自动完成)。问题是无论我尝试什么方法,我都无法更新“列表”。我可以将无限内容添加到光标,但旧的仍然存在,我不希望这样。我不知道如何解决它:(。

如果您有任何问题,请随时提出,我会尽力解释等。

最佳答案

已修复。基本上我重置了适配器,将新光标设置为主要内容。我之前尝试过,但没有用,因为我没有将 searchView 设置为全局(在类里面)。使其成为全局后,我可以使用 searchView 并设置新的适配器,使其工作。换句话说:

mSuggestionsAdapter = new SuggestionsAdapter(getSupportActionBar()
.getThemedContext(), tempCur);

searchView.setSuggestionsAdapter(mSuggestionsAdapter);

关于android - setSuggestionAdapter cursor - 需要更新它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22597422/

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