Android Open Source - BLEService Characteristics 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  a v  a2s  . c  o m*/
import java.util.ArrayList;
import java.util.Locale;

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

public class CharacteristicsListAdapter extends BaseAdapter {
      private ArrayList<BluetoothGattCharacteristic> mCharacteristics;
      private LayoutInflater mInflater;
      public CharacteristicsListAdapter(Activity parent) {
        mCharacteristics  = new ArrayList<BluetoothGattCharacteristic>();
        mInflater = parent.getLayoutInflater();
      public void addCharacteristic(BluetoothGattCharacteristic ch) {
        if(mCharacteristics.contains(ch) == false) {
      public BluetoothGattCharacteristic getCharacteristic(int index) {
        return mCharacteristics.get(index);

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

    public Object getItem(int position) {
      return getCharacteristic(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_characteristic_item, null);
              fields = new FieldReferences();
              fields.charName = (TextView)convertView.findViewById(;
              fields.charUuid = (TextView)convertView.findViewById(;
            } else {
                fields = (FieldReferences) convertView.getTag();
            // set proper values into the view
            BluetoothGattCharacteristic ch = getCharacteristic(position);
            String uuid = ch.getUuid().toString().toLowerCase(Locale.getDefault());
            String name = BleNamesResolver.resolveCharacteristicName(uuid);
      return convertView;
    private class FieldReferences {
      TextView charName;
      TextView charUuid;

Java Source Code List