I am creating a app to play music.
Upon entering the app, a list (ListView) of all the playlists show. When clicking on the item (playlist) in the ListView, it opens the playlist and displays all the songs. All of this works.
I am now trying to add a menu to the right side of each item. When clicking on the menu button I want "code b" to run, while clicking on the item, I want "code a" to run. Here is how I create the items:
public static void createList(final MainActivity mainActivity, ListView listView) {
final ArrayList<Playlist> playlists = getLists();
playlists.sort(new Comparator<Playlist>() {
@Override
public int compare(Playlist playlist1, Playlist playlist2) {
return playlist1.name.compareTo(playlist2.name);
}
});
ArrayList<String> playlistsText = new ArrayList<>();
for (Playlist playlist : playlists)
playlistsText.add(playlist.name);
ArrayAdapter<String> adapter = new ArrayAdapter<>(mainActivity, android.R.layout.simple_list_item_1, playlistsText);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
new PlaylistFragment(mainActivity, playlists.get(position));
}
});
}
Here is the XML code:
<ListView
android:id="@+id/playlist_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:dividerHeight="1dp" />
Is there an easy way to add some sort of button to the right of each item in the ListView? The only way I can think is to use a relative layout somehow as the items in the ListView, which I can populate with a Button and ImageButton.
This menu would be used for things like "Remove Playlist" and "Copy Playlist".
Thanks in advance!