[問題] 想請問Hashtable<Key,Values>的問題
發出求救信號~
我有一個Hashtable<Key,Values>
裡面的Values一直更新
想要判斷Values連續10次相同就remove掉這個device的array
我有寫出大概意思的code不過不知道怎麼下手,因我的mRssi會一直更新
public ArrayList<BluetoothDevice> mLeDevices = new ArrayList<BluetoothDevice>();
public ArrayList<byte[]> mRecords = new ArrayList<byte[]>();
public Hashtable<String, Integer> mRssi = new Hashtable<>();
public void addDevice(BluetoothDevice device, int rssi, byte[] scanRecord) {
if (!mLeDevices.contains(device)) {
mLeDevices.add(device);
mRecords.add(scanRecord);
}
mRssi.put(device.getAddress(), rssi);
/** 以下為意識code */
ArrayList<Integer> rssiArrayList = new ArrayList<Integer>(mRssi.values());
int lastNum = rssiArrayList.get();
int count = 0;
/** 從頭開始loop */
for (int i = 0; i < rssiArrayList.size(); i++) {
/** 如果當前值等於最後值 */
if(rssiArrayList[i]==lastNum){
count++;
if(count>=10){
/** 如果連續10次rssi相同就移除 */
mLeDevices.remove();
}
}
/** 如果不相等的話 */
else {
lastNum=rssiArrayList[i];
count = 1;
}
}
Log.e("mRssi", String.valueOf(mRssi));
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.161.11.105
※ 文章網址: https://www.ptt.cc/bbs/java/M.1449740510.A.347.html
推
12/11 00:32, , 1F
12/11 00:32, 1F
→
12/11 00:32, , 2F
12/11 00:32, 2F
→你好,就是我的藍芽在掃瞄,
然後要顯示在RecyclerView上,
當我掃瞄到的時候添加進去,
可是當我把藍芽裝置的電池拔開的時候,
沒偵測到了,
需要自動remove掉那個item,
希望有simple code可以提供~
已經用盡我自己的方式還是不行真是不好意思呢
→
12/11 05:39, , 3F
12/11 05:39, 3F
有比較具體一點的code嗎,不好意思
※ 編輯: freedom74569 (61.230.134.93), 12/11/2015 07:39:00
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
java 近期熱門文章
PTT數位生活區 即時熱門文章