0

I'm writing an app which is playing music (and movies later). I added some menu items like shuffle, repeat song, exit etc. and all works like a charm. But I can't get the search button working (to search for requested song name). Here are errors from log cat when I used debugger, entered app and clicked the magnifying glass/search button:

LogCat

Floyd ish
  • 1
  • 2
  • post your code for reference? – Rajan Kali Oct 25 '14 at 16:33
  • Here are the fragments of code where search button is used [link](http://wklej.org/id/1498747/) I tried to add this function using this tutorial [link](http://antonioleiva.com/actionbarcompat-action-views/) – Floyd ish Oct 25 '14 at 16:56

1 Answers1

0

//global declaration

public SearchView mSearchView;

//try this in setup searchmethod

  public boolean onCreateOptionsMenu(Menu menu) {
        // action bar items
        getMenuInflater().inflate(R.menu.moj_media_play, menu);
        menu.findItem(R.id.action_search).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS
               |MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
               mSearchView = (SearchView) MenuItem.getActionView(menu.findItem(R.id.action_search));
        return true;

    }

//onoptionsitemSelected

public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.action_rand:
              mojMedPl.setShuffle();
                Toast.makeText(getBaseContext(), "Odtwarzanie losowe włączone", Toast.LENGTH_LONG).show();      
              break;
        case R.id.action_end:
              stopService(playIntent);
              mojMedPl=null;
              System.exit(0);
              break;
        case R.id.action_repeat:
             mojMedPl.setRepeat();   
            // if(mojMedPl.checkRepeat=true)
            Toast.makeText(getBaseContext(), "Powtarzanie włączone", Toast.LENGTH_LONG).show(); 
            // else     Toast.makeText(getBaseContext(), "Powtarzanie wyłączone", Toast.LENGTH_LONG).show();    
              break;
        case R.id.action_search:
             mSearchView.setOnQueryTextListener(this);

            // mSearchView.setIconified(false); 

             return true;

        }
        return false;
        //return super.onOptionsItemSelected(item);
    }
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37