【问题标题】:How to get the array from the given class Item?如何从给定的类Item中获取数组?
【发布时间】:2016-07-09 15:19:59
【问题描述】:

首先,我是一个新手,我正在尝试使用 mediastore 获取媒体文件的详细信息,并将详细信息保存在列表 mitems 中。这就是我正在做的事情

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

在这里,我从内部和外部 uri 获取文件详细信息并将它们保存在 arraylist 中。但我无法获得特定列的详细信息。这就是我正在尝试的

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) {
    this.id = 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);
}
}

如何从另一个类或片段中的 Item 类中获取以下详细信息作为数组。

【问题讨论】:

    标签: java android class arraylist


    【解决方案1】:

    你可以像这样得到你的数组项。前this is the example

    for(int i =0; i<= mItem.size(); i++){
            String songName = mItem.get(i).getArtist();
            String songAlbum = mItem.get(i).getAlbum();
        }
    
    1. 如果您想将数据设置为列表视图,您可以这样设置。

      首先全局设置这个变量。

      ListAdapter myadapter;

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

      在 onCreate 方法中使用如下:

     for(int i = 0; i<=mItem.size();i++)
     {
         songList.add(mItem.get(i).getArtist());
     }
    
     myadapter = new ArrayAdapter<String>         
    (YourActivity.this, android.R.layout.simple_list_item_1, songList);
    

    我希望它有效。

    【讨论】:

      猜你喜欢
      • 2010-12-13
      • 2023-01-31
      • 1970-01-01
      • 2019-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-21
      相关资源
      最近更新 更多