'Use items from a view in an ArrayAdapter in another Activity
I am building a Music Player. I have succeeded in adding the setOnItemClickListener on the view. Now if I click on the views displayed from the ArrayAdapter, it opens a new activity (PlayActivity). However, I want to display some items (artiste name, song title and image) shown on the initial view clicked, in the new PlayActivity.
// Get a reference to the ListView, and attach the adapter to the listView.
ListView listView = findViewById(R.id.song_list);
listView.setAdapter(libraryAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
// Create a new intent to open {@link NumbersActivity}
Intent playSongIntent = new Intent(LibraryActivity.this, PlayActivity.class);
// Start new activity
startActivity(playSongIntent);
}```
Library Class
```public class Library {
// Name of song
private String mSongTitle;
// Name of artist
private String mArtisteName;
// Drawable resource ID
private int mImageResourceId;
/**
* Create a new Album Object
*
* @param vSongTitle is the title of the song
* @param vArtisteName is the name of the artiste
* @param image is drawable reference ID
*/
public Library(String vSongTitle, String vArtisteName, int image) {
mSongTitle = vSongTitle;
mArtisteName = vArtisteName;
mImageResourceId = image;
}
/**
* Get the title of song
*/
public String getSongTitle() {
return mSongTitle;
}
/**
* Get the name of artiste
*/
public String getArtisteName() {
return mArtisteName;
}
/**
* Get the image resource ID
*/
public int getImageResourceId() {
return mImageResourceId;
}
}```
How do I use those three data shown on the view from the ArrayAdapter clicked on the new PlayActivity which will show a view of the song playing?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
