如何从给定的类Item获取数组? [英] How to get the array from the given class Item?

查看:86
本文介绍了如何从给定的类Item获取数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是新手,我试图使用mediastore获取媒体文件的详细信息,并将详细信息保存在列表mitems中.这是我在做什么

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 mitems. 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>();

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

Here I am getting the file details from internal and external uri and saving them in arraylist. 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) {
    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类作为数组获取以下详细信息.

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

推荐答案

,您可以像这样获得数组项.例如,这是示例

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. 如果要将数据设置为列表视图,则可以这样设置.

  1. if you want set your data to listview you can set like this.

首先全局设置此变量.

ListAdapter myadapter;

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

和onCreate方法中的用法如下:

and in onCreate Method use like this:

 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);

我希望它能起作用.

这篇关于如何从给定的类Item获取数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆