Android Open Source - BLEService Services List Adapter

From Project

Back to project page BLEService.


The source code is released under:

Copyright (c) 2014, Ratio LLC. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project BLEService listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.bluetooth.bledemo;
/* w w w  . j ava2  s . c om*/
import java.util.ArrayList;
import java.util.Locale;

import android.bluetooth.BluetoothGattService;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/* display all services for particular device */
public class ServicesListAdapter extends BaseAdapter {
  private ArrayList<BluetoothGattService> mBTServices;
  private LayoutInflater mInflater;
  public ServicesListAdapter(Activity parent) {
    mBTServices  = new ArrayList<BluetoothGattService>();
    mInflater = parent.getLayoutInflater();
  public void addService(BluetoothGattService service) {
    if(mBTServices.contains(service) == false) {
  public BluetoothGattService getService(int index) {
    return mBTServices.get(index);

  public void clearList() {
  public int getCount() {
    return mBTServices.size();

  public Object getItem(int position) {
    return getService(position);

  public long getItemId(int position) {
    return position;

  public View getView(int position, View convertView, ViewGroup parent) {
    // get already available view or create new if necessary
    FieldReferences fields;
        if (convertView == null) {
          convertView = mInflater.inflate(R.layout.peripheral_list_services_item, null);
          fields = new FieldReferences();
          fields.serviceName = (TextView)convertView.findViewById(;
          fields.serviceUuid = (TextView)convertView.findViewById(;
          fields.serviceType = (TextView)convertView.findViewById(;
        } else {
            fields = (FieldReferences) convertView.getTag();
        // set proper values into the view
        BluetoothGattService service = mBTServices.get(position);
        String uuid = service.getUuid().toString().toLowerCase(Locale.getDefault());
        String name = BleNamesResolver.resolveServiceName(uuid);
        String type = (service.getType() == BluetoothGattService.SERVICE_TYPE_PRIMARY) ? "Primary" : "Secondary";

    return convertView;
  private class FieldReferences {
    TextView serviceName;
    TextView serviceUuid;
    TextView serviceType;

Java Source Code List