package com.launcher.yd.adapter;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ApplicationsAdapter extends ArrayAdapter {
    public class ViewHolder {
        public ImageView image;
        public TextView title;
    }
    private LayoutInflater inflater;
    private ArrayList mApplications;
    private Context mContext;
    public ApplicationsAdapter(Context context, ArrayList arraylist) {
        super(context, 0, arraylist);
        mContext = context;
        inflater = LayoutInflater.from(context);
        mApplications = arraylist;
    }
    @Override
    public int getCount() {
        if (mApplications != null) return mApplications.size();
        else return 0;
    }
    @Override
    public ApplicationInfo getItem(int i) {
        return (ApplicationInfo) mApplications.get(i);
    }
    @Override
    public long getItemId(int i) {
        return i;
    }
    @Override
    public View getView(int i, View view, ViewGroup viewgroup) {
        ApplicationInfo applicationinfo = (ApplicationInfo) mApplications.get(i);
        ViewHolder viewholder;
        if (view == null) {
            viewholder = new ViewHolder();
            view = inflater.inflate(biz.AR.layout.sub_app_item, null);
            viewholder.title = (TextView) view.findViewById(biz.AR.id.apps_item_title);
            viewholder.image = (ImageView) view.findViewById(biz.AR.id.apps_item_icon);
            view.setTag(viewholder);
        } else {
            viewholder = (ViewHolder) view.getTag();
        }
        viewholder.title.setText(applicationinfo.title);
        viewholder.image.setBackground(applicationinfo.icon);
        return view;
    }
}
