package orz.ludysu.lrcjaeger;

import java.util.ArrayList;

import orz.ludysu.lrcjaeger.R;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class SongItemAdapter extends ArrayAdapter<SongItem> {
    private LayoutInflater mInflater = null;
    private ArrayList<SongItem> mSongs;
    private OnLrcClickListener mLrcListener;
    
    public interface OnLrcClickListener {
        public void OnLrcClick(int position);
    }

    public SongItemAdapter(Context context, ArrayList<SongItem> songs) {
        super(context, 0, songs);
        mInflater = LayoutInflater.from(context);
        mSongs = songs;
    }
    
    public void setLrcClickListener(OnLrcClickListener l) {
        mLrcListener = l;
    }
    
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.song_item, parent, false);
        }
        
        SongItem song = mSongs.get(position);
        
        TextView title = (TextView) convertView.findViewById(R.id.tv_song_title);
        title.setText(song.getTitle());
        
        TextView artist = (TextView) convertView.findViewById(R.id.tv_song_artist);
        artist.setText(song.getArtist());

        int color = song.isHasLrc() ? Color.argb(255, 0, 162, 232) : Color.LTGRAY;
        TextView hasLrc = (TextView) convertView.findViewById(R.id.tv_has_lrc);
        hasLrc.setTextColor(color);
        
        hasLrc.setClickable(true);
        hasLrc.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mLrcListener.OnLrcClick(position);
            }
        });
        
        return convertView;
    }

}

@@ -28,69 +28,8 @@
 r;%0A%0A
-import java.util.ArrayList;%0A%0Aimport orz.ludysu.lrcjaeger.R;%0A%0A
 impo
@@ -56,16 +56,16 @@
 ontext;%0A
+
 import a
@@ -291,16 +291,45 @@
 tView;%0A%0A
+import java.util.ArrayList;%0A%0A
 public c
@@ -892,28 +892,162 @@
  = l;%0A    %7D%0A
+%0A
     
+private class ViewHolder %7B%0A        TextView mTitle;%0A        TextView mArtist;%0A        TextView mHasLrc;%0A        int mPosition;%0A    %7D%0A
 %0A    @Overri
@@ -1127,24 +1127,52 @@
 p parent) %7B%0A
+        ViewHolder holder;%0A%0A
         if (
@@ -1270,24 +1270,472 @@
 nt, false);%0A
+            holder = new ViewHolder();%0A            holder.mTitle = (TextView) convertView.findViewById(R.id.tv_song_title);%0A            holder.mArtist = (TextView) convertView.findViewById(R.id.tv_song_artist);%0A            holder.mHasLrc = (TextView) convertView.findViewById(R.id.tv_has_lrc);%0A            holder.mPosition = position;%0A            convertView.setTag(holder);%0A        %7D else %7B%0A            holder = (ViewHolder) convertView.getTag();%0A
         %7D%0A  
@@ -1732,25 +1732,17 @@
       %7D%0A
-        
 %0A
+
         
@@ -1779,24 +1779,16 @@
 ition);%0A
-        
 %0A       
@@ -1792,224 +1792,65 @@
     
-TextView title = (TextView) convertView.findViewById(R.id.tv_song_title);%0A        title.setText(song.getTitle());%0A        %0A        TextView artist = (TextView) convertView.findViewById(R.id.tv_song_artist);%0A        a
+holder.mTitle.setText(song.getTitle());%0A        holder.mA
 rtis
@@ -1992,60 +1992,22 @@
 c = 
-(TextView) convertView.findViewById(R.id.tv_has_l
+holder.mHasL
 rc
-)
 ;%0A  

Add a view holder in adapter to avoid findViewById multiple times