ResourceAdapter.java 1.55 KB
package com.upc.pbe.upcnews;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ResourceAdapter extends ArrayAdapter<String>
{

    Context context; 
    int layoutResourceId;    
    String[] entries = null;
    
    public ResourceAdapter(Context context, int layoutResourceId, String[] data) 
    {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        entries = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
    	 TextView row;
    	 
         if (convertView == null) 
         {
        	 LayoutInflater inflater = ((Activity)context).getLayoutInflater();
             row = (TextView) inflater.inflate(R.layout.rowlayout, parent, false);
         } 
         else 
         {
             row = (TextView) convertView;
         }

         final String text = entries[position];
         row.setText(text);
	     if(text.endsWith(".m3u8")) //Playlists
	     {
	       	//row.setTypeface(null, Typeface.BOLD);
	       	row.setTextColor(Color.parseColor("#5FB404"));
	     }
	     else //Normal entries
	     {
	    	 row.setTypeface(null,Typeface.NORMAL);
	    	 row.setTextColor(((Activity)context).getResources().getColor(R.color.BlueAndroid));
	     }
        return row;
    }
}