@Override
    public View getView(int i, View view, ViewGroup viewGroup) {
      ViewHolder viewHolder;
      // General ListView optimization code.
      if (view == null) {
        view = mInflator.inflate(R.layout.listitem_device, null);
        viewHolder = new ViewHolder();
        viewHolder.deviceAddress = (TextView) view.findViewById(R.id.device_address);
        viewHolder.deviceName = (TextView) view.findViewById(R.id.device_name);
        view.setTag(viewHolder);
      } else {
        viewHolder = (ViewHolder) view.getTag();
      }

      BluetoothDevice device = mLeDevices.get(i);
      final String deviceName = device.getName();
      SharedPreferences prefs =
          PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
      if (prefs.getString("last_connected_device_address", "").compareTo(device.getAddress())
          == 0) {
        viewHolder.deviceName.setTextColor(ChartUtils.COLOR_BLUE);
        viewHolder.deviceAddress.setTextColor(ChartUtils.COLOR_BLUE);
      }
      viewHolder.deviceName.setText(deviceName);
      viewHolder.deviceAddress.setText(device.getAddress());
      return view;
    }
  @Override
  public View getView(int i, View view, ViewGroup viewGroup) {
    ViewHolder viewHolder;
    // General ListView optimization code.
    if (view == null) {
      view = mInflator.inflate(R.layout.list_item_device, null);
      viewHolder = new ViewHolder();
      viewHolder.deviceAddress = (TextView) view.findViewById(R.id.device_address);
      viewHolder.deviceName = (TextView) view.findViewById(R.id.device_name);
      viewHolder.deviceRssi = (TextView) view.findViewById(R.id.device_rssi);
      viewHolder.deviceLastUpdated = (TextView) view.findViewById(R.id.device_last_update);
      viewHolder.ibeaconMajor = (TextView) view.findViewById(R.id.ibeacon_major);
      viewHolder.ibeaconMinor = (TextView) view.findViewById(R.id.ibeacon_minor);
      viewHolder.ibeaconDistance = (TextView) view.findViewById(R.id.ibeacon_distance);
      viewHolder.ibeaconUUID = (TextView) view.findViewById(R.id.ibeacon_uuid);
      viewHolder.ibeaconTxPower = (TextView) view.findViewById(R.id.ibeacon_tx_power);
      viewHolder.ibeaconSection = view.findViewById(R.id.ibeacon_section);
      viewHolder.ibeaconDistanceDescriptor =
          (TextView) view.findViewById(R.id.ibeacon_distance_descriptor);
      view.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) view.getTag();
    }

    final BluetoothLeDevice device = getCursor().getItem(i);
    final String deviceName = device.getName();
    final double rssi = device.getRssi();

    if (deviceName != null && deviceName.length() > 0) {
      viewHolder.deviceName.setText(deviceName);
    } else {
      viewHolder.deviceName.setText(R.string.unknown_device);
    }

    if (IBeaconUtils.isThisAnIBeacon(device)) {
      final IBeaconDevice iBeacon = new IBeaconDevice(device);
      final String accuracy = Constants.DOUBLE_TWO_DIGIT_ACCURACY.format(iBeacon.getAccuracy());

      viewHolder.ibeaconSection.setVisibility(View.VISIBLE);
      viewHolder.ibeaconMajor.setText(String.valueOf(iBeacon.getMajor()));
      viewHolder.ibeaconMinor.setText(String.valueOf(iBeacon.getMinor()));
      viewHolder.ibeaconTxPower.setText(String.valueOf(iBeacon.getCalibratedTxPower()));
      viewHolder.ibeaconUUID.setText(iBeacon.getUUID());
      viewHolder.ibeaconDistance.setText(mActivity.getString(R.string.formatter_meters, accuracy));
      viewHolder.ibeaconDistanceDescriptor.setText(iBeacon.getDistanceDescriptor().toString());
    } else {
      viewHolder.ibeaconSection.setVisibility(View.GONE);
    }

    final String rssiString = mActivity.getString(R.string.formatter_db, String.valueOf(rssi));
    final String runningAverageRssiString =
        mActivity.getString(R.string.formatter_db, String.valueOf(device.getRunningAverageRssi()));

    viewHolder.deviceLastUpdated.setText(
        android.text.format.DateFormat.format(
            Constants.TIME_FORMAT, new java.util.Date(device.getTimestamp())));
    viewHolder.deviceAddress.setText(device.getAddress());
    viewHolder.deviceRssi.setText(rssiString + " / " + runningAverageRssiString);
    return view;
  }
 public void setViewHolder(View view) {
   ViewHolder viewHolder = new ViewHolder();
   viewHolder.deviceName = (TextView) view.findViewById(R.id.deviceName);
   viewHolder.deviceAddress = (TextView) view.findViewById(R.id.deviceAddress);
   viewHolder.deviceIcon = (ImageView) view.findViewById(R.id.deviceIcon);
   viewHolder.selected = (RadioButton) view.findViewById(R.id.selected);
   view.setTag(viewHolder);
 }
    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
      ViewHolder viewHolder;
      // General ListView optimization code.
      if (view == null) {
        view = mInflator.inflate(R.layout.listitem_open_device, null);
        viewHolder = new ViewHolder();
        viewHolder.deviceStatus = (TextView) view.findViewById(R.id.device_status);
        viewHolder.deviceName = (TextView) view.findViewById(R.id.device_name);
        viewHolder.closeButton = (Button) view.findViewById(R.id.close_button);
        viewHolder.closeButton.setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                BluetoothMidiDeviceTracker deviceTracker = mOpenDevices.get(i);
                doClose(deviceTracker.midiDevice);
                ((Button) v).setEnabled(false);
              }
            });
        view.setTag(viewHolder);
      } else {
        viewHolder = (ViewHolder) view.getTag();
      }

      BluetoothMidiDeviceTracker deviceTracker = mOpenDevices.get(i);
      final String deviceName = deviceTracker.bluetoothDevice.getName();
      if (deviceName != null && deviceName.length() > 0) {
        viewHolder.deviceName.setText(deviceName);
      } else {
        viewHolder.deviceName.setText("--");
      }

      // Show address and number of ports open.
      StringBuilder sb = new StringBuilder();
      sb.append(" - ");
      sb.append(deviceTracker.bluetoothDevice.getAddress());
      sb.append(", [" + deviceTracker.inputOpenCount);
      sb.append("][" + deviceTracker.outputOpenCount);
      sb.append("]");

      if ((deviceTracker.inputOpenCount + deviceTracker.outputOpenCount) > 0) {
        sb.append(" in use");
      }
      viewHolder.deviceStatus.setText(sb.toString());

      return view;
    }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
      ViewHolder viewHolder;
      if (view == null) {
        view = mInflator.inflate(R.layout.listitem_device, null);
        viewHolder = new ViewHolder();
        viewHolder.deviceAddress = (TextView) view.findViewById(R.id.device_address);
        viewHolder.deviceName = (TextView) view.findViewById(R.id.device_name);
        view.setTag(viewHolder);
      } else {
        viewHolder = (ViewHolder) view.getTag();
      }

      BLEDevice device = mDevices.get(i);
      final String deviceName = device.getMAC();
      if (deviceName != null && deviceName.length() > 0) viewHolder.deviceName.setText(deviceName);
      else viewHolder.deviceName.setText(R.string.unknown_device);
      viewHolder.deviceAddress.setText(device.getUUID());

      return view;
    }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
      ViewHolder viewHolder;
      // General ListView optimization code.
      if (view == null) {
        view = mInflator.inflate(R.layout.listitem_device, null);
        viewHolder = new ViewHolder();
        viewHolder.deviceAddress = (TextView) view.findViewById(R.id.device_address);
        viewHolder.deviceName = (TextView) view.findViewById(R.id.device_name);
        System.out.println("mInflator.inflate  getView");
        view.setTag(viewHolder);
      } else {
        viewHolder = (ViewHolder) view.getTag();
      }

      BluetoothDevice device = mLeDevices.get(i);
      final String deviceName = device.getName();
      if (deviceName != null && deviceName.length() > 0) viewHolder.deviceName.setText(deviceName);
      else viewHolder.deviceName.setText(R.string.unknown_device);
      viewHolder.deviceAddress.setText(device.getAddress());

      return view;
    }