How to get the string value of the item selected from a listview












-1















I have a custom adaptor that is fills a listview with artists names. I want to click on the listview artist and it will return me the list of songs by the artist. I want to get the string value of the artist when i click on the listview and compare it against an arraylist of all the songs



   public void getSongList() {
//retrieve song info
ContentResolver musicResolver = getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
musicCursor = musicResolver.query(musicUri, null, null, null, null);
if(musicCursor!=null && musicCursor.moveToFirst()){
//get columns
int titleColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.ARTIST);
//add songs to list
do {

long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
songs.add(new Song(thisId,thisTitle,thisArtist));}
while (musicCursor.moveToNext());
}

}




artistLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

Toast.makeText(getApplicationContext(),"am:", Toast.LENGTH_SHORT).show();
ArrayList<Song> temp = new ArrayList<>();
for (Song song : songs){
strong text
if (song.getArtist().equals("Foo Fighters")){
temp.add(song);
}
}
songs = temp;
SongAdapter songAdt = new SongAdapter(getApplication(), songs);
artistLV.setAdapter(songAdt);
}
});









share|improve this question



























    -1















    I have a custom adaptor that is fills a listview with artists names. I want to click on the listview artist and it will return me the list of songs by the artist. I want to get the string value of the artist when i click on the listview and compare it against an arraylist of all the songs



       public void getSongList() {
    //retrieve song info
    ContentResolver musicResolver = getContentResolver();
    Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    musicCursor = musicResolver.query(musicUri, null, null, null, null);
    if(musicCursor!=null && musicCursor.moveToFirst()){
    //get columns
    int titleColumn = musicCursor.getColumnIndex
    (android.provider.MediaStore.Audio.Media.TITLE);
    int idColumn = musicCursor.getColumnIndex
    (android.provider.MediaStore.Audio.Media._ID);
    int artistColumn = musicCursor.getColumnIndex
    (android.provider.MediaStore.Audio.Media.ARTIST);
    //add songs to list
    do {

    long thisId = musicCursor.getLong(idColumn);
    String thisTitle = musicCursor.getString(titleColumn);
    String thisArtist = musicCursor.getString(artistColumn);
    songs.add(new Song(thisId,thisTitle,thisArtist));}
    while (musicCursor.moveToNext());
    }

    }




    artistLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

    Toast.makeText(getApplicationContext(),"am:", Toast.LENGTH_SHORT).show();
    ArrayList<Song> temp = new ArrayList<>();
    for (Song song : songs){
    strong text
    if (song.getArtist().equals("Foo Fighters")){
    temp.add(song);
    }
    }
    songs = temp;
    SongAdapter songAdt = new SongAdapter(getApplication(), songs);
    artistLV.setAdapter(songAdt);
    }
    });









    share|improve this question

























      -1












      -1








      -1








      I have a custom adaptor that is fills a listview with artists names. I want to click on the listview artist and it will return me the list of songs by the artist. I want to get the string value of the artist when i click on the listview and compare it against an arraylist of all the songs



         public void getSongList() {
      //retrieve song info
      ContentResolver musicResolver = getContentResolver();
      Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
      musicCursor = musicResolver.query(musicUri, null, null, null, null);
      if(musicCursor!=null && musicCursor.moveToFirst()){
      //get columns
      int titleColumn = musicCursor.getColumnIndex
      (android.provider.MediaStore.Audio.Media.TITLE);
      int idColumn = musicCursor.getColumnIndex
      (android.provider.MediaStore.Audio.Media._ID);
      int artistColumn = musicCursor.getColumnIndex
      (android.provider.MediaStore.Audio.Media.ARTIST);
      //add songs to list
      do {

      long thisId = musicCursor.getLong(idColumn);
      String thisTitle = musicCursor.getString(titleColumn);
      String thisArtist = musicCursor.getString(artistColumn);
      songs.add(new Song(thisId,thisTitle,thisArtist));}
      while (musicCursor.moveToNext());
      }

      }




      artistLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

      Toast.makeText(getApplicationContext(),"am:", Toast.LENGTH_SHORT).show();
      ArrayList<Song> temp = new ArrayList<>();
      for (Song song : songs){
      strong text
      if (song.getArtist().equals("Foo Fighters")){
      temp.add(song);
      }
      }
      songs = temp;
      SongAdapter songAdt = new SongAdapter(getApplication(), songs);
      artistLV.setAdapter(songAdt);
      }
      });









      share|improve this question














      I have a custom adaptor that is fills a listview with artists names. I want to click on the listview artist and it will return me the list of songs by the artist. I want to get the string value of the artist when i click on the listview and compare it against an arraylist of all the songs



         public void getSongList() {
      //retrieve song info
      ContentResolver musicResolver = getContentResolver();
      Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
      musicCursor = musicResolver.query(musicUri, null, null, null, null);
      if(musicCursor!=null && musicCursor.moveToFirst()){
      //get columns
      int titleColumn = musicCursor.getColumnIndex
      (android.provider.MediaStore.Audio.Media.TITLE);
      int idColumn = musicCursor.getColumnIndex
      (android.provider.MediaStore.Audio.Media._ID);
      int artistColumn = musicCursor.getColumnIndex
      (android.provider.MediaStore.Audio.Media.ARTIST);
      //add songs to list
      do {

      long thisId = musicCursor.getLong(idColumn);
      String thisTitle = musicCursor.getString(titleColumn);
      String thisArtist = musicCursor.getString(artistColumn);
      songs.add(new Song(thisId,thisTitle,thisArtist));}
      while (musicCursor.moveToNext());
      }

      }




      artistLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

      Toast.makeText(getApplicationContext(),"am:", Toast.LENGTH_SHORT).show();
      ArrayList<Song> temp = new ArrayList<>();
      for (Song song : songs){
      strong text
      if (song.getArtist().equals("Foo Fighters")){
      temp.add(song);
      }
      }
      songs = temp;
      SongAdapter songAdt = new SongAdapter(getApplication(), songs);
      artistLV.setAdapter(songAdt);
      }
      });






      android android-studio






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 14:45









      Arjun LimbuArjun Limbu

      11




      11
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Song selectedSong = songs.get(i); // this will object of data of the selected song


          then use



          selectedSong.getArtist();


          and it will return you the artist of the song that you selected






          share|improve this answer


























          • thank that will work good

            – Arjun Limbu
            Nov 24 '18 at 15:00



















          0














          Add these lines inside your onItemClick method



          TextView artistTextView = (TextView) view.findViewById(R.id.yourTextViewReference);
          String artistName= artistTextView.getText().toString();





          share|improve this answer
























          • How it is going to give detail of selected item of listview

            – Lekr0
            Nov 24 '18 at 15:12











          • there are two ways which i know you can retrieve data from listview rows first way is the one which @Jawad has told and second one is like this

            – Shehroz
            Nov 24 '18 at 15:17











          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%2f53459306%2fhow-to-get-the-string-value-of-the-item-selected-from-a-listview%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Song selectedSong = songs.get(i); // this will object of data of the selected song


          then use



          selectedSong.getArtist();


          and it will return you the artist of the song that you selected






          share|improve this answer


























          • thank that will work good

            – Arjun Limbu
            Nov 24 '18 at 15:00
















          0














          Song selectedSong = songs.get(i); // this will object of data of the selected song


          then use



          selectedSong.getArtist();


          and it will return you the artist of the song that you selected






          share|improve this answer


























          • thank that will work good

            – Arjun Limbu
            Nov 24 '18 at 15:00














          0












          0








          0







          Song selectedSong = songs.get(i); // this will object of data of the selected song


          then use



          selectedSong.getArtist();


          and it will return you the artist of the song that you selected






          share|improve this answer















          Song selectedSong = songs.get(i); // this will object of data of the selected song


          then use



          selectedSong.getArtist();


          and it will return you the artist of the song that you selected







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 24 '18 at 15:07









          Lekr0

          357212




          357212










          answered Nov 24 '18 at 14:54









          Jawad AhmedJawad Ahmed

          776




          776













          • thank that will work good

            – Arjun Limbu
            Nov 24 '18 at 15:00



















          • thank that will work good

            – Arjun Limbu
            Nov 24 '18 at 15:00

















          thank that will work good

          – Arjun Limbu
          Nov 24 '18 at 15:00





          thank that will work good

          – Arjun Limbu
          Nov 24 '18 at 15:00













          0














          Add these lines inside your onItemClick method



          TextView artistTextView = (TextView) view.findViewById(R.id.yourTextViewReference);
          String artistName= artistTextView.getText().toString();





          share|improve this answer
























          • How it is going to give detail of selected item of listview

            – Lekr0
            Nov 24 '18 at 15:12











          • there are two ways which i know you can retrieve data from listview rows first way is the one which @Jawad has told and second one is like this

            – Shehroz
            Nov 24 '18 at 15:17
















          0














          Add these lines inside your onItemClick method



          TextView artistTextView = (TextView) view.findViewById(R.id.yourTextViewReference);
          String artistName= artistTextView.getText().toString();





          share|improve this answer
























          • How it is going to give detail of selected item of listview

            – Lekr0
            Nov 24 '18 at 15:12











          • there are two ways which i know you can retrieve data from listview rows first way is the one which @Jawad has told and second one is like this

            – Shehroz
            Nov 24 '18 at 15:17














          0












          0








          0







          Add these lines inside your onItemClick method



          TextView artistTextView = (TextView) view.findViewById(R.id.yourTextViewReference);
          String artistName= artistTextView.getText().toString();





          share|improve this answer













          Add these lines inside your onItemClick method



          TextView artistTextView = (TextView) view.findViewById(R.id.yourTextViewReference);
          String artistName= artistTextView.getText().toString();






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 15:08









          ShehrozShehroz

          10216




          10216













          • How it is going to give detail of selected item of listview

            – Lekr0
            Nov 24 '18 at 15:12











          • there are two ways which i know you can retrieve data from listview rows first way is the one which @Jawad has told and second one is like this

            – Shehroz
            Nov 24 '18 at 15:17



















          • How it is going to give detail of selected item of listview

            – Lekr0
            Nov 24 '18 at 15:12











          • there are two ways which i know you can retrieve data from listview rows first way is the one which @Jawad has told and second one is like this

            – Shehroz
            Nov 24 '18 at 15:17

















          How it is going to give detail of selected item of listview

          – Lekr0
          Nov 24 '18 at 15:12





          How it is going to give detail of selected item of listview

          – Lekr0
          Nov 24 '18 at 15:12













          there are two ways which i know you can retrieve data from listview rows first way is the one which @Jawad has told and second one is like this

          – Shehroz
          Nov 24 '18 at 15:17





          there are two ways which i know you can retrieve data from listview rows first way is the one which @Jawad has told and second one is like this

          – Shehroz
          Nov 24 '18 at 15:17


















          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%2f53459306%2fhow-to-get-the-string-value-of-the-item-selected-from-a-listview%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

          Wiesbaden

          Marschland

          Dieringhausen