Actionbarsherlock搜索查看:setOnQueryTextListenerActionbarsherlock、setOnQueryTextListener

2023-09-06 05:05:29 作者:一席青衣卧龙城

我试图让使用ActionBarSherlock的搜索视图列表中的过滤器。在code我现在有如下:

I'm trying to make a filter in a List using ActionBarSherlock's search view. The code I currently have is the following:

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getSupportMenuInflater().inflate(R.menu.building_search, menu);

    SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());

    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() 
    {
        public boolean onQueryTextChange(String newText) 
        {
            // this is your adapter that will be filtered
            listAdapter.getFilter().filter(newText);
            return true;
        }

        public boolean onQueryTextSubmit(String query) 
        {
            // this is your adapter that will be filtered
            listAdapter.getFilter().filter(query);
            return true;
        }
    };
    searchView.setOnQueryTextListener(queryTextListener);

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.search:
            onSearchRequested();
            return true;
    }
    return super.onOptionsItemSelected(item);
}

这些都是我进口:

import android.os.Bundle;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import be.ugent.zeus.hydra.AbstractSherlockActivity;
import be.ugent.zeus.hydra.R;
import be.ugent.zeus.hydra.data.caches.AssociationsCache;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.widget.SearchView;
import com.dd.plist.NSArray;
import com.dd.plist.NSDictionary;
import com.dd.plist.NSString;
import com.dd.plist.XMLPropertyListParser;
import com.emilsjolander.components.stickylistheaders.StickyListHeadersListView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;

大多数的工作原理:在我的动作条,我得到一个搜索图标,这是可以点击的,扩大了搜索查看。什么,但是,不工作是实际的听众。我已经把断点两种方法里面,但是当我调试,没有任何反应。该方案不破,没有什么被过滤,我想不出为什么。

Most of it works: in my actionbar, I get a search icon, which is clickable and expands the searchview. What, however, doesn't work is the actual listener. I've put breakpoints inside both methods, but when I debug, nothing happens. The program doesn't break and nothing gets filtered and I can't figure out why.

有没有人有任何想法?

在此先感谢。

推荐答案

由于所有其他的答案中包含了一点道理,但并不能完全回答这个问题,我会创造我自己的答案。

As every other answer contained a bit of truth, but didn't answer the question fully, I'll create my own answer.

当这个问题被创造 - 半年前 - ABS没有完全实现搜索查看功能。由于ABS 4.2.0的,这已经得到落实。

When this issue was created - half a year ago - ABS did not fully implement the SearchView functionality. As of ABS 4.2.0, this has been implemented.

我的全面实施,按照该ABS示例应用程序,可以发现 。

My full implementation, by following the ABS sample app, can be found here.

 
精彩推荐
图片推荐