0

我想使用我实现的 getfilter() 但从操作栏中搜索我的 listview 。但不知道为什么应用程序不断给出空指针,我也无法理解错误。这是我的代码调用我的自定义 getfilter 实现在我的自定义适配器中。

public static class DummySectionFragment extends Fragment {
    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    public static final String ARG_SECTION_NUMBER = "section_number";

    ListView itcItems;
    DataBaseHandler db;
    private SearchView mSearchView;
    //private EditText mStatusView;

    public DummySectionFragment() {
    }

    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

         //MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.option_menu, menu); 

        //getMenuInflater().inflate(R.menu.action, menu);   


        searchView = (SearchView) menu.findItem(R.id.Search).getActionView();
        SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); 
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchView.setIconifiedByDefault(false);   

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





    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        setHasOptionsMenu(true);

        View rootView = inflater.inflate(R.layout.common_listview,
                container, false);
        setHasOptionsMenu(true);


        ActionBar actionbar = getActivity().getActionBar();
        getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        actionbar.show();
         //getActivity().requestWindowFeature(Window.FEATURE_ACTION_BAR);
         //mStatusView = (EditText) rootView.findViewById(R.id.status_text);
        itcItems = (ListView) rootView.findViewById(R.id.streamList);



        /*MyAsyncTask task = new MyAsyncTask(getActivity());
        task.execute("http://findaway.in/card/restlist.xml");


        *
        */
        db = new DataBaseHandler(getActivity());

        if(isOnline(getActivity()))

        { 
            flag=1;
            db.delete();
            getDataInAsyncTask();

            getImage(db);
            //db.close();

        }

        else
        {
            flag=0;
            Toast.makeText(getActivity(), "No internet",
                    Toast.LENGTH_LONG).show();

            try {
                db.openDataBase();
            } catch (SQLException sqle) {
                throw sqle;
            }

            getDataInDataBase(db);


        }

这是我的日志猫 在此处输入图像描述

第 212 行是 searchView = (SearchView) menu.findItem(R.id.Search).getActionView();

还必须实现 res/xml/searchable.xml 吗?我没有那样做

4

1 回答 1

0

在 onCreateOptionsMenu() 中,缺少对 super 的调用。考虑使用 super,然后使用 inflater 和 menu 对象。

于 2014-02-10T06:03:00.670 回答