package cis470.adpater.custom;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class ArrayAdapterDemo8 extends ListActivity {
	TextView txtMsg;
	String[] items = {  "Data-1", "Data-2", "Data-3", "Data-4",
			"Data-5", "Data-6", "Data-7",
			"Data-8", "Data-9", "Data-10",
			"Data-11", "Data-12", "Data-13",
			"Data-14", "Data-15" };
	
	Integer[] thumbnails = { R.drawable.pic01_small,
			R.drawable.pic02_small, R.drawable.pic03_small,
			R.drawable.pic04_small, R.drawable.pic05_small,
			R.drawable.pic06_small, R.drawable.pic07_small,
			R.drawable.pic08_small, R.drawable.pic09_small, 
			R.drawable.pic10_small, R.drawable.pic11_small, 
			R.drawable.pic12_small, R.drawable.pic13_small, 
			R.drawable.pic14_small, R.drawable.pic15_small };
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.main);

		setListAdapter(new CustomIconLabelAdapter(this, 
				                          items, thumbnails));

		txtMsg = (TextView) findViewById(R.id.txtMsg);
	}

	public void onListItemClick(ListView parent, View v, int position, long id) {
		txtMsg.setText(items[position]);
	}
	// ////////////////////////////////////////////////////////////
	class CustomIconLabelAdapter extends ArrayAdapter {
		Context context;
		Integer[] thumbnails;
		String[] items;
		
		CustomIconLabelAdapter(Context context, String[] items, Integer[] thumbnails) {
			super(context, R.layout.row_icon_label, items);
			this.context = context;	
			this.thumbnails = thumbnails;
			this.items = items;
		}
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			
			View row = inflater.inflate(R.layout.row_icon_label, null);
			
			TextView label = (TextView) row.findViewById(R.id.label);
			ImageView icon = (ImageView) row.findViewById(R.id.icon);
			
			label.setText(items[position]);
			icon.setImageResource( thumbnails[position] );
			
			
			return (row);
		}// getView

	}// IconicAdapter

}// ArrayAdapterDemo8

