Android Open Source - ponyville-live-android Track List Adapter

From Project

Back to project page ponyville-live-android.


The source code is released under:

Apache License

If you think the Android project ponyville-live-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

//  w  w  w. j  a v  a2 s.c o m
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.Collections;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

 * Created by berwyn on 21/08/14.
public class TrackListAdapter extends BaseAdapter {

    private List<SongWrapper> songs;

    public TrackListAdapter() {
        this.songs = Collections.emptyList();

    public void setSongs(List<SongWrapper> songs) {
        this.songs = songs;

    public void addSongs(List<SongWrapper> songs) {

    public int getCount() {
        return songs.size();

    public Song getItem(int position) {
        return songs.get(position).song;

    public long getItemId(int position) {
        return position;

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            convertView = inflater.inflate(R.layout.view_track_list_item, parent, false);
            vh = new ViewHolder();
            ButterKnife.inject(vh, convertView);
        } else {
            vh = ((ViewHolder) convertView.getTag());

        Song song = getItem(position);
        vh.title.setText(song.title == null? "[NO DATA]" : song.title);
        vh.artist.setText(song.artist == null? "[NO DATA]": song.artist);

        return convertView;

    class ViewHolder {
        TextView title;
        TextView artist;

Java Source Code List