Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android setSuggestionAdapter光标-需要更新它_Android_Search_Autocomplete_Actionbarsherlock - Fatal编程技术网

Android setSuggestionAdapter光标-需要更新它

Android setSuggestionAdapter光标-需要更新它,android,search,autocomplete,actionbarsherlock,Android,Search,Autocomplete,Actionbarsherlock,所以,我有两行: @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getSupportMenuInflater().inflate(R.menu.onime_main, menu); // Create the search view SearchView searchView = new SearchView(getSuppo

所以,我有两行:

@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;
}
@覆盖
公共布尔onQueryTextChange(字符串newText){
//TODO自动生成的方法存根
Log.e(“测试:”,新文本);
List temp=db.getSuggestion(newText);
MatrixCursor tempCur=新的MatrixCursor(列);
用于(序列号cn:temp){
tempCur.addRow(新字符串[]{cn.getID()+“”,cn.getName()});
Log.e(“Info:,cn.getID()+”“+cn.getName());
}
游标=临时电流;
用于(序列号cn:temp){
字符串log=“Id:”+cn.getID()+”,名称:“+cn.getName()
+,Description:“+cn.getDescription();
//将联系人写入日志
Log.d(“名称:”,Log);
}
mSuggestionsAdapter.notifyDataSetChanged();
返回false;
}
这个想法很简单。我有“搜索框”,无论我键入什么,都会有新的文本。这将是发送sql查询,从中我可以获得所需的数据(用于自动完成)。问题是,无论我尝试什么方法,我都无法更新“列表”。我可以将无限的内容添加到光标上,但旧的内容仍然存在,我不希望这样。我再也不知道怎么解决它了


如果您有任何问题,请随时提问,我将尝试解释或诸如此类的问题。

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

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

    searchView.setSuggestionsAdapter(mSuggestionsAdapter);