Implementing searchView in MainActivity.java action bar to search for content in other activity












0















I am new in Android Studio. I have an app which has a main activity compromising if a menu and inside each menu item is a listView of objects.Each object contains 2 textView, an image and an audio file. When an item in the list is clicked, a particular audio file is played.I would like to insert an autoComplete search view in the mainActivity action bar so that a user can search for an item in any activity in a list and when he finds it and clicks it, the audio file is played. Here is a snippet of my mainActivity.java file



private AdView mAdView;
GridView gridview;

public static String osNameList = {
"NUMBERS",
"FAMILY",
"COLORS",
"NOUNS",
"VERBS",
"PHRASES",
"ANIMALS",
"DATES"
};
public static int osImages = {
R.drawable.numbers,
R.drawable.family,
R.drawable.colors,
R.drawable.nouns,
R.drawable.verbs,
R.drawable.phrases,
R.drawable.pawprint,
R.drawable.dates
};



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

gridview = (GridView) findViewById(R.id.grid);
gridview.setAdapter(new adapter(Main2Activity.this, osNameList, osImages));


Here is a snippet of my grid adapter



rowView.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (position == 0){
context.startActivity(new Intent(context, NumbersActivity.class));
}
else if (position == 1){
context.startActivity(new Intent(context, FamilyActivity.class));
}
else if (position == 2){
context.startActivity(new Intent(context, ColorsActivity.class));
}
else if (position == 3){
context.startActivity(new Intent(context, NounsActivityFrags.class));
}
else if (position == 4){
context.startActivity(new Intent(context, VerbsActivity.class));
}
else if (position == 5){
context.startActivity(new Intent(context, PhrasesActivityFrags.class));
}
else if (position == 6){
context.startActivity(new Intent(context, Animals.class));
}
else if (position == 7){
context.startActivity(new Intent(context, CalendarActivityFrags.class));
}
}
});


Here is a snippet of one of my activities containing the objects in a listView



final ArrayList<Word> word = new ArrayList<Word>();

word.add(new Word("one","kunye",R.drawable.one,R.raw.one));
word.add(new Word("two","kubili",R.drawable.two,R.raw.two));
word.add(new Word("three","kuthathu",R.drawable.three,R.raw.three));
word.add(new Word("four","kune",R.drawable.four,R.raw.four));
word.add(new Word("five","kuhlanu",R.drawable.five,R.raw.five));
word.add(new Word("six","sithandathu",R.drawable.six,R.raw.six));
word.add(new Word("seven","likhomba",R.drawable.seven,R.raw.seven));
word.add(new Word("eight","bunane",R.drawable.eight,R.raw.eight));
word.add(new Word("nine","lithoba",R.drawable.nine,R.raw.nine));
word.add(new Word("ten","itjhumi",R.drawable.ten,R.raw.ten));
word.add(new Word("COUNT ONE TO TEN","",R.raw.onetoten));



WordAdapter adapter = new WordAdapter(this, word, R.color.category_numbers);
ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Word sound = word.get(position);

//Release the media player if it currently exists because we are about to play a different audio file
releaseMediaPlayer();

// Request audio focus for playback
int result = mAudioManager.requestAudioFocus(afChangeListener,
// Use the music stream.
AudioManager.STREAM_MUSIC,
// Request permanent focus.
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
// we have audio focus now



mMediaPlayer = MediaPlayer.create(NumbersActivity.this, sound.getmAudioResourceId());
mMediaPlayer.start();
Toast.makeText(NumbersActivity.this, "Now Playing...", Toast.LENGTH_SHORT).show();

mMediaPlayer.setOnCompletionListener(mOnCompletionListener);
}
}
});

}


I want user to be able to search using the english word but be able to find the whole object










share|improve this question





























    0















    I am new in Android Studio. I have an app which has a main activity compromising if a menu and inside each menu item is a listView of objects.Each object contains 2 textView, an image and an audio file. When an item in the list is clicked, a particular audio file is played.I would like to insert an autoComplete search view in the mainActivity action bar so that a user can search for an item in any activity in a list and when he finds it and clicks it, the audio file is played. Here is a snippet of my mainActivity.java file



    private AdView mAdView;
    GridView gridview;

    public static String osNameList = {
    "NUMBERS",
    "FAMILY",
    "COLORS",
    "NOUNS",
    "VERBS",
    "PHRASES",
    "ANIMALS",
    "DATES"
    };
    public static int osImages = {
    R.drawable.numbers,
    R.drawable.family,
    R.drawable.colors,
    R.drawable.nouns,
    R.drawable.verbs,
    R.drawable.phrases,
    R.drawable.pawprint,
    R.drawable.dates
    };



    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    gridview = (GridView) findViewById(R.id.grid);
    gridview.setAdapter(new adapter(Main2Activity.this, osNameList, osImages));


    Here is a snippet of my grid adapter



    rowView.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    if (position == 0){
    context.startActivity(new Intent(context, NumbersActivity.class));
    }
    else if (position == 1){
    context.startActivity(new Intent(context, FamilyActivity.class));
    }
    else if (position == 2){
    context.startActivity(new Intent(context, ColorsActivity.class));
    }
    else if (position == 3){
    context.startActivity(new Intent(context, NounsActivityFrags.class));
    }
    else if (position == 4){
    context.startActivity(new Intent(context, VerbsActivity.class));
    }
    else if (position == 5){
    context.startActivity(new Intent(context, PhrasesActivityFrags.class));
    }
    else if (position == 6){
    context.startActivity(new Intent(context, Animals.class));
    }
    else if (position == 7){
    context.startActivity(new Intent(context, CalendarActivityFrags.class));
    }
    }
    });


    Here is a snippet of one of my activities containing the objects in a listView



    final ArrayList<Word> word = new ArrayList<Word>();

    word.add(new Word("one","kunye",R.drawable.one,R.raw.one));
    word.add(new Word("two","kubili",R.drawable.two,R.raw.two));
    word.add(new Word("three","kuthathu",R.drawable.three,R.raw.three));
    word.add(new Word("four","kune",R.drawable.four,R.raw.four));
    word.add(new Word("five","kuhlanu",R.drawable.five,R.raw.five));
    word.add(new Word("six","sithandathu",R.drawable.six,R.raw.six));
    word.add(new Word("seven","likhomba",R.drawable.seven,R.raw.seven));
    word.add(new Word("eight","bunane",R.drawable.eight,R.raw.eight));
    word.add(new Word("nine","lithoba",R.drawable.nine,R.raw.nine));
    word.add(new Word("ten","itjhumi",R.drawable.ten,R.raw.ten));
    word.add(new Word("COUNT ONE TO TEN","",R.raw.onetoten));



    WordAdapter adapter = new WordAdapter(this, word, R.color.category_numbers);
    ListView listView = (ListView) findViewById(R.id.list);
    listView.setAdapter(adapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Word sound = word.get(position);

    //Release the media player if it currently exists because we are about to play a different audio file
    releaseMediaPlayer();

    // Request audio focus for playback
    int result = mAudioManager.requestAudioFocus(afChangeListener,
    // Use the music stream.
    AudioManager.STREAM_MUSIC,
    // Request permanent focus.
    AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

    if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
    // we have audio focus now



    mMediaPlayer = MediaPlayer.create(NumbersActivity.this, sound.getmAudioResourceId());
    mMediaPlayer.start();
    Toast.makeText(NumbersActivity.this, "Now Playing...", Toast.LENGTH_SHORT).show();

    mMediaPlayer.setOnCompletionListener(mOnCompletionListener);
    }
    }
    });

    }


    I want user to be able to search using the english word but be able to find the whole object










    share|improve this question



























      0












      0








      0








      I am new in Android Studio. I have an app which has a main activity compromising if a menu and inside each menu item is a listView of objects.Each object contains 2 textView, an image and an audio file. When an item in the list is clicked, a particular audio file is played.I would like to insert an autoComplete search view in the mainActivity action bar so that a user can search for an item in any activity in a list and when he finds it and clicks it, the audio file is played. Here is a snippet of my mainActivity.java file



      private AdView mAdView;
      GridView gridview;

      public static String osNameList = {
      "NUMBERS",
      "FAMILY",
      "COLORS",
      "NOUNS",
      "VERBS",
      "PHRASES",
      "ANIMALS",
      "DATES"
      };
      public static int osImages = {
      R.drawable.numbers,
      R.drawable.family,
      R.drawable.colors,
      R.drawable.nouns,
      R.drawable.verbs,
      R.drawable.phrases,
      R.drawable.pawprint,
      R.drawable.dates
      };



      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main2);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);

      gridview = (GridView) findViewById(R.id.grid);
      gridview.setAdapter(new adapter(Main2Activity.this, osNameList, osImages));


      Here is a snippet of my grid adapter



      rowView.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
      // TODO Auto-generated method stub
      if (position == 0){
      context.startActivity(new Intent(context, NumbersActivity.class));
      }
      else if (position == 1){
      context.startActivity(new Intent(context, FamilyActivity.class));
      }
      else if (position == 2){
      context.startActivity(new Intent(context, ColorsActivity.class));
      }
      else if (position == 3){
      context.startActivity(new Intent(context, NounsActivityFrags.class));
      }
      else if (position == 4){
      context.startActivity(new Intent(context, VerbsActivity.class));
      }
      else if (position == 5){
      context.startActivity(new Intent(context, PhrasesActivityFrags.class));
      }
      else if (position == 6){
      context.startActivity(new Intent(context, Animals.class));
      }
      else if (position == 7){
      context.startActivity(new Intent(context, CalendarActivityFrags.class));
      }
      }
      });


      Here is a snippet of one of my activities containing the objects in a listView



      final ArrayList<Word> word = new ArrayList<Word>();

      word.add(new Word("one","kunye",R.drawable.one,R.raw.one));
      word.add(new Word("two","kubili",R.drawable.two,R.raw.two));
      word.add(new Word("three","kuthathu",R.drawable.three,R.raw.three));
      word.add(new Word("four","kune",R.drawable.four,R.raw.four));
      word.add(new Word("five","kuhlanu",R.drawable.five,R.raw.five));
      word.add(new Word("six","sithandathu",R.drawable.six,R.raw.six));
      word.add(new Word("seven","likhomba",R.drawable.seven,R.raw.seven));
      word.add(new Word("eight","bunane",R.drawable.eight,R.raw.eight));
      word.add(new Word("nine","lithoba",R.drawable.nine,R.raw.nine));
      word.add(new Word("ten","itjhumi",R.drawable.ten,R.raw.ten));
      word.add(new Word("COUNT ONE TO TEN","",R.raw.onetoten));



      WordAdapter adapter = new WordAdapter(this, word, R.color.category_numbers);
      ListView listView = (ListView) findViewById(R.id.list);
      listView.setAdapter(adapter);

      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      Word sound = word.get(position);

      //Release the media player if it currently exists because we are about to play a different audio file
      releaseMediaPlayer();

      // Request audio focus for playback
      int result = mAudioManager.requestAudioFocus(afChangeListener,
      // Use the music stream.
      AudioManager.STREAM_MUSIC,
      // Request permanent focus.
      AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

      if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
      // we have audio focus now



      mMediaPlayer = MediaPlayer.create(NumbersActivity.this, sound.getmAudioResourceId());
      mMediaPlayer.start();
      Toast.makeText(NumbersActivity.this, "Now Playing...", Toast.LENGTH_SHORT).show();

      mMediaPlayer.setOnCompletionListener(mOnCompletionListener);
      }
      }
      });

      }


      I want user to be able to search using the english word but be able to find the whole object










      share|improve this question
















      I am new in Android Studio. I have an app which has a main activity compromising if a menu and inside each menu item is a listView of objects.Each object contains 2 textView, an image and an audio file. When an item in the list is clicked, a particular audio file is played.I would like to insert an autoComplete search view in the mainActivity action bar so that a user can search for an item in any activity in a list and when he finds it and clicks it, the audio file is played. Here is a snippet of my mainActivity.java file



      private AdView mAdView;
      GridView gridview;

      public static String osNameList = {
      "NUMBERS",
      "FAMILY",
      "COLORS",
      "NOUNS",
      "VERBS",
      "PHRASES",
      "ANIMALS",
      "DATES"
      };
      public static int osImages = {
      R.drawable.numbers,
      R.drawable.family,
      R.drawable.colors,
      R.drawable.nouns,
      R.drawable.verbs,
      R.drawable.phrases,
      R.drawable.pawprint,
      R.drawable.dates
      };



      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main2);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);

      gridview = (GridView) findViewById(R.id.grid);
      gridview.setAdapter(new adapter(Main2Activity.this, osNameList, osImages));


      Here is a snippet of my grid adapter



      rowView.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
      // TODO Auto-generated method stub
      if (position == 0){
      context.startActivity(new Intent(context, NumbersActivity.class));
      }
      else if (position == 1){
      context.startActivity(new Intent(context, FamilyActivity.class));
      }
      else if (position == 2){
      context.startActivity(new Intent(context, ColorsActivity.class));
      }
      else if (position == 3){
      context.startActivity(new Intent(context, NounsActivityFrags.class));
      }
      else if (position == 4){
      context.startActivity(new Intent(context, VerbsActivity.class));
      }
      else if (position == 5){
      context.startActivity(new Intent(context, PhrasesActivityFrags.class));
      }
      else if (position == 6){
      context.startActivity(new Intent(context, Animals.class));
      }
      else if (position == 7){
      context.startActivity(new Intent(context, CalendarActivityFrags.class));
      }
      }
      });


      Here is a snippet of one of my activities containing the objects in a listView



      final ArrayList<Word> word = new ArrayList<Word>();

      word.add(new Word("one","kunye",R.drawable.one,R.raw.one));
      word.add(new Word("two","kubili",R.drawable.two,R.raw.two));
      word.add(new Word("three","kuthathu",R.drawable.three,R.raw.three));
      word.add(new Word("four","kune",R.drawable.four,R.raw.four));
      word.add(new Word("five","kuhlanu",R.drawable.five,R.raw.five));
      word.add(new Word("six","sithandathu",R.drawable.six,R.raw.six));
      word.add(new Word("seven","likhomba",R.drawable.seven,R.raw.seven));
      word.add(new Word("eight","bunane",R.drawable.eight,R.raw.eight));
      word.add(new Word("nine","lithoba",R.drawable.nine,R.raw.nine));
      word.add(new Word("ten","itjhumi",R.drawable.ten,R.raw.ten));
      word.add(new Word("COUNT ONE TO TEN","",R.raw.onetoten));



      WordAdapter adapter = new WordAdapter(this, word, R.color.category_numbers);
      ListView listView = (ListView) findViewById(R.id.list);
      listView.setAdapter(adapter);

      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      Word sound = word.get(position);

      //Release the media player if it currently exists because we are about to play a different audio file
      releaseMediaPlayer();

      // Request audio focus for playback
      int result = mAudioManager.requestAudioFocus(afChangeListener,
      // Use the music stream.
      AudioManager.STREAM_MUSIC,
      // Request permanent focus.
      AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

      if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
      // we have audio focus now



      mMediaPlayer = MediaPlayer.create(NumbersActivity.this, sound.getmAudioResourceId());
      mMediaPlayer.start();
      Toast.makeText(NumbersActivity.this, "Now Playing...", Toast.LENGTH_SHORT).show();

      mMediaPlayer.setOnCompletionListener(mOnCompletionListener);
      }
      }
      });

      }


      I want user to be able to search using the english word but be able to find the whole object







      java android listview searchview






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 7:45









      Aniruddh Parihar

      2,20911027




      2,20911027










      asked Nov 21 '18 at 7:43









      Tinovimba MawoyoTinovimba Mawoyo

      475




      475
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407333%2fimplementing-searchview-in-mainactivity-java-action-bar-to-search-for-content-in%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407333%2fimplementing-searchview-in-mainactivity-java-action-bar-to-search-for-content-in%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?