Neelay Srivastava Neelay Srivastava - 1 year ago 39
Java Question

How to get the array from the given class Item?

First of all i am a newbie and I am trying to get the media files details using mediastore and saving the details in the List

. Here is what I am doing

public class MusicRetriever {
final String TAG = "MusicRetriever";
ContentResolver mContentResolver;
// the items (songs) we have queried
List<Item> mItems = new ArrayList<Item>();

Here I am getting the file details from internal and external uri and saving them in
. But I am not able to get the details of particular column. This is what i am trying

public class Item {
long id;
String artist;
String title;
String album;
long duration;

public Item(long id, String artist, String title, String album, long duration) { = id;
this.artist = artist;
this.title = title;
this.album = album;
this.duration = duration;

public long getId() {
return id;

public String getArtist() {
return artist;

public String getTitle() {
return title;

public String getAlbum() {
return album;

public long getDuration() {
return duration;

public Uri getURI() {
return ContentUris.withAppendedId(
android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id);

How I can get the following details as an array from Item class in another class or fragment.

Answer Source

you can get your array item like this. exthis is the example

for(int i =0; i<= mItem.size(); i++){
        String songName = mItem.get(i).getArtist();
        String songAlbum = mItem.get(i).getAlbum();
  1. if you want set your data to listview you can set like this.

    first set this variable globally.

    ListAdapter myadapter;

    ArrayList<String> songList = new ArrayList<String>();

    and in onCreate Method use like this:

 for(int i = 0; i<=mItem.size();i++)

 myadapter = new ArrayAdapter<String>         
(YourActivity.this, android.R.layout.simple_list_item_1, songList);

I hope it works.