Created
September 9, 2018 00:10
-
-
Save coding-catie/7593189fe6452a48e07637a13008cf4b to your computer and use it in GitHub Desktop.
MusicPlayer-example MySongsList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.catie.musicplayerapp; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.widget.ListView; | |
import com.example.catie.musicplayerapp.R; | |
import com.example.catie.musicplayerapp.Song; | |
import com.example.catie.musicplayerapp.SongAdapter; | |
import java.util.ArrayList; | |
public class MySongsList extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_my_songs_list); | |
// Create a list of song titles and their artists | |
ArrayList<Song> songs = new ArrayList<Song>(); | |
songs.add(new Song("Hey Jude", "The Beatles")); | |
songs.add(new Song("Eye of the Tiger", "Survivor")); | |
songs.add(new Song("Every Breath You Take", "The Police")); | |
songs.add(new Song("The Battle of New Orleans", "Johnny Horton")); | |
songs.add(new Song("Another One Bites the Dust", "Queen")); | |
songs.add(new Song("How You Remind Me", "Nickelback")); | |
songs.add(new Song("Stayin' Alive", "Bee Gees")); | |
songs.add(new Song("Stairway to Heaven", "Led Zeppelin")); | |
songs.add(new Song("Walk This Way", "Aerosmith")); | |
songs.add(new Song("Gimme Shelter", "The Rolling Stones")); | |
// Create an {@link SongAdapter}, whose data source is a list of {@link Song}s. The | |
// adapter knows how to create list items for each item in the list. | |
SongAdapter adapter = new SongAdapter(this, songs); | |
// Find the {@link ListView} object in the view hierarchy of the {@link Activity}. | |
// There should be a {@link ListView} with the view ID called list, which is declared in the | |
// my_songs_list file. | |
ListView listView = (ListView) findViewById(R.id.list); | |
// Make the {@link ListView} use the {@link SongAdapter} we created above, so that the | |
// {@link ListView} will display list items for each {@link Song} in the list. | |
listView.setAdapter(adapter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment