0

how can I put multiple objects from List into one textview in ListAdapter? Here is my code:

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_music_browser);
musichelper msc = new musichelper(this);
List<HashMap<String, String>> musics = msc.buildMusic();
ListView lv = (ListView)findViewById(R.id.listView);

ListAdapter la = new SimpleAdapter(this, musics, R.layout.song_list,
        new String[] { "artist"+" - "+"title", "duration" }, new int[] { R.id.pickerName, R.id.pickerLength }
        );
lv.setAdapter(la);

This ends up having no artist and no title but I want it to be like: Artist - Song Name assigned to TextView called R.id.pickerName.

Also duration is in milliseconds, how can I convert it directly when building ListAdapter? I want milliseconds for example: 414616 to be written as: 7:31 (I think)

enter image description here

This is what I end up with when trying to combine Artist + - + Title. And as you see - duration appears in milliseconds.

I know I could do all of the above when building the List of objects but I would like to keep them as seperate objects.

arleitiss
  • 1,304
  • 1
  • 14
  • 38

1 Answers1

0

The String array is a mapping of the key in the HashMap to the list.

In msc.buildMusic(), when you are adding the duration to the HashMap you need to change the milliseconds to the format you want. Then you add the String with the format into the hashmap instead of the milliseconds. Also, you will need to add a new line that puts the artist and the title into the HashMap with the key artist - title. (I recommend you remove the spacing)

Community
  • 1
  • 1