在 recyclerview 上添加 mp3 文件

adding mp3 file on recyclerview

您好,我创建了 arecyclerview 应用程序。当我单击一个项目时,它显示文本和图像,但我想添加 r.raw.b mp3 文件作为第三个项目。我该怎么做? 这里有详细的activity。我怎样才能改变它们?如果有人帮忙,非常感谢..

Bundle mBundle = getIntent().getExtras();
    if (mBundle != null) {
    mToolbar.setTitle(mBundle.getString("Title"));
    mFlower.setImageResource(mBundle.getInt("Image"));
    mDescription.setText(mBundle.getString("Description"));

这里是主页:

GridLayoutManager mGridLayoutManager = new GridLayoutManager(MainActivity.this, 2);
    mRecyclerView.setLayoutManager(mGridLayoutManager);

    mFlowerList = new ArrayList<>();
    mFlowerData = new FlowerData("Rose", getString(R.string.description_flower_rose),
            R.drawable.rose,R.raw.b);

这是我的适配器:

  @Override
public void onBindViewHolder(final FlowerViewHolder holder, int position) {
    holder.mImage.setImageResource(mFlowerList.get(position).getFlowerImage());
    holder.mTitle.setText(mFlowerList.get(position).getFlowerName());
    holder.mCardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent mIntent = new Intent(mContext, DetailActivity.class);
            mIntent.putExtra("Title", mFlowerList.get(holder.getAdapterPosition()).getFlowerName());
            mIntent.putExtra("Description", mFlowerList.get(holder.getAdapterPosition()).getFlowerDescription());
            mIntent.putExtra("Image", mFlowerList.get(holder.getAdapterPosition()).getFlowerImage());
            mContext.startActivity(mIntent);
        }
    });

public class PlaylistActivity 扩展 AppCompatActivity {

private RecyclerView recyclerView;
private SongsAdapter songsAdapter;
SongsManager songsManager;
String MEDIA_PATH = Environment.getExternalStorageDirectory() + "";
ArrayList<HashMap<String, String>> songList=new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_playlist);
    recyclerView=(RecyclerView)findViewById(R.id.playlistactivityrecyclerview);
    songsManager=new SongsManager();
 songList =songsManager.getPlayList(MEDIA_PATH);
    songsAdapter=new SongsAdapter(songList);
    recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
    recyclerView.setAdapter(songsAdapter);
    Toast.makeText(getApplicationContext(),"Hi",Toast.LENGTH_LONG).show();
}

}

public class 歌曲管理器 {

public ArrayList<HashMap<String, String>> getPlayList(String rootPath) {
    ArrayList<HashMap<String, String>> fileList = new ArrayList<>();

    try {
        File rootFolder = new File(rootPath);
        File[] files = rootFolder.listFiles(); //here you will get NPE if directory doesn't contains  any file,handle it like this.
        for (File file : files) {
            if (file.isDirectory()) {
                if (getPlayList(file.getAbsolutePath()) != null) {
                    fileList.addAll(getPlayList(file.getAbsolutePath()));
                } else {
                    break;
                }
            } else if (file.getName().endsWith(".mp3")) {
                HashMap<String, String> song = new HashMap<>();
                song.put("file_path", file.getAbsolutePath());
                song.put("file_name", file.getName());
                fileList.add(song);
            }
        }
        return fileList;
    } catch (Exception e) {
        return null;
    }
}

}