【发布时间】:2014-05-01 02:27:40
【问题描述】:
所以,我有这两行:
@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;
}
想法很简单。我有“搜索框”,无论我输入什么都会有 newText。将发送 sql 查询,我将在其中获得所需的数据(用于自动完成)。问题是无论我尝试什么方法,我都无法更新“列表”。我可以将无限内容添加到光标,但旧的内容仍然存在,我不想要那个。我不知道如何解决它了:(。
如果您有任何问题,请随时提出,我会尽力解释或类似的。
【问题讨论】:
标签: android search autocomplete actionbarsherlock