从每个ListView项目获取RSSI值并将其存储在数组中-Android Studio

问题描述

我是Android Studio的新手。我使用Kelvin Aviles' BLE Scanner code作为接近感应应用程序的基础。扫描结束时,我希望能够获取每个发现的设备的RSSI值并将其存储在数组中。我打算最终根据大小对数组进行排序。

这是listadapter代码

public class listadapter_BTLE_Devices extends ArrayAdapter<BTLE_Device> {

Activity activity;
int layoutResourceID;
ArrayList<BTLE_Device> devices;

public listadapter_BTLE_Devices(Activity activity,int resource,ArrayList<BTLE_Device> objects) {
    super(activity.getApplicationContext(),resource,objects);

    this.activity = activity;
    layoutResourceID = resource;
    devices = objects;
}

@Override
public View getView(int position,View convertView,ViewGroup parent) {

    if (convertView == null) {
        LayoutInflater inflater =
                (LayoutInflater) activity.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(layoutResourceID,parent,false);
    }

    BTLE_Device device = devices.get(position);
    String name = device.getName();
    String address = device.getAddress();
    int RSSi = device.getRSSI();
    TextView tv = null;

    tv = (TextView) convertView.findViewById(R.id.tv_name);
    if (name != null && name.length() > 0) {
        tv.setText(device.getName());
    }
    else {
        tv.setText("No Name");
    }

    tv = (TextView) convertView.findViewById(R.id.tv_dist);
    double dist = calculatedistance(-59,RSSi);
    tv.setText("distance: " + (double) Math.round(dist*100)/100 + "\n");

    tv = (TextView) convertView.findViewById(R.id.tv_RSSi);
    tv.setText("RSSI: " + RSSi);

    tv = (TextView) convertView.findViewById(R.id.tv_macaddr);
    if (address != null && address.length() > 0) {
        tv.setText(device.getAddress());
        //tv.setText(device);
    }
    else {
        tv.setText("No Address");
    }


    return convertView;
}


public double calculatedistance(int txPower,double RSSi) {
    //calculations go here
    return distance;
}

出现在应用程序中的ListView:

enter image description here

我希望能够创建一个在这种情况下将包含“ -65,-95,-83,-94”或相应距离值的数组。请注意,在扫描过程中,RSSI值将不断变化。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)