Created
April 24, 2018 01:58
-
-
Save eltonjhony/c08f7b2b11b9018f0735c5ffc30ff6e8 to your computer and use it in GitHub Desktop.
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.android.appmusica; | |
import android.app.Activity; | |
import android.support.annotation.NonNull; | |
import android.support.annotation.Nullable; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ArrayAdapter; | |
import android.widget.TextView; | |
import java.util.ArrayList; | |
public class MusicAdapter extends ArrayAdapter<Music> { | |
private OnOpenMusicListener listener; | |
public MusicAdapter(Activity context, ArrayList<Music> words, @NonNull OnOpenMusicListener listener){ | |
super(context, 0, words); | |
this.listener = listener; | |
} | |
@NonNull | |
@Override | |
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { | |
View listItemView = convertView; | |
if(listItemView == null) { | |
listItemView = LayoutInflater.from(getContext()).inflate( | |
R.layout.activity_list_item, parent, false); | |
} | |
final Music currentMusic = getItem(position); | |
TextView textViewMusica = (TextView) listItemView.findViewById(R.id.text_view_musica); | |
TextView textViewArtista = (TextView) listItemView.findViewById(R.id.text_view_artista); | |
textViewMusica.setText(currentMusic.getDefaultMusica()); | |
textViewArtista.setText((currentMusic.getDefaultArtista())); | |
listItemView.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
listener.onClick(currentMusic); | |
} | |
}); | |
return listItemView; | |
} | |
public interface OnOpenMusicListener { | |
void onClick(Music music); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment