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-0", "Data-1", "Data-2", "Data-3", "Data-4",
			"Data-5", "Data-6", "Data-7" };

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.main);

		setListAdapter(new CustomIconLabelAdapter(this));

		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;
		
		CustomIconLabelAdapter(Context context) {
			super(context, R.layout.row_icon_label, items);
			this.context = context;			
		}
		@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]);
		
			if (position % 2 == 0)
				icon.setImageResource(R.drawable.notok);
			else
				icon.setImageResource(R.drawable.ok);
			return (row);
		}// getView

	}// IconicAdapter

}// ArrayAdapterDemo8

