package com.seikoinstruments.sdk.thermalprinter.sample;

import java.util.List;

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

public class BluetoothDeviceListArrayAdapter extends ArrayAdapter<BluetoothDeviceListItem> {

    /** Create view from xml */
    private LayoutInflater mLayoutInflater;


    public BluetoothDeviceListArrayAdapter(Context context, List<BluetoothDeviceListItem> objects) {
        super(context, 0, objects);
        mLayoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(android.R.layout.simple_list_item_2, null);
        }

        final BluetoothDeviceListItem item = this.getItem(position);
        if(item != null){
            final TextView deviceNameTxt = (TextView)convertView.findViewById(android.R.id.text1);
            deviceNameTxt.setText(item.getDeviceName());

            final TextView deviceAddressTxt = (TextView)convertView.findViewById(android.R.id.text2);
            deviceAddressTxt.setText(item.getDeviceAddress());

        }
        return convertView;
    }

}
