[问题] 有关于拿不到Arraylist的问题

楼主: freedom74569   2015-12-28 12:59:07
https://www.ptt.cc/bbs/AndroidDev/M.1451090467.A.79A.html
这是上次的问题,
我有抓到问题了,
我implements library然后使用里面的fuction
//宣告ArrayList mDevices1
public ArrayList<BluetoothDevice> mDevices1 = new ArrayList<BluetoothDevice>();
//使用library function,还是这里会做在library package里面,这样让我取不到?
@Override
public void bluetoothDeviceListBeenRenewed(BluetoothList bluetoothList) {
//mDevices1 = bluetoothList;
mDevices1.addAll(bluetoothList);
// 这里打印的出来mDevices01,而且bluelist确定有东西也有打印出来
Log.e("mDevices1", String.valueOf(mLeDevices1));
}
我只有在这个function印得出来mDevices1,
不过在如onCreate or 其他地方要拿来用,
就拿不到mDevices1就为空的阵列
存不回去上面宣告的mDevices1那
我想问看看有什么关键字!
现在完全没有方向...
作者: jknm0510a (Kang)   2015-12-28 13:24:00
你先放log看oncreate先还是这个function先如果callback函式,再create是还没执行就是null如果不是这样,就是另外的原因了
楼主: freedom74569   2015-12-28 13:26:00
onCreate先执行,我有点抓不太到方向
作者: jknm0510a (Kang)   2015-12-28 13:51:00
function执行才有塞值,在还没塞值就问他答案,当然会是null
楼主: freedom74569   2015-12-28 14:48:00
可是我有用个loop循环让他一直塞,刚刚测试了一下,在外面给他一个String XX="1",然后fun把它设成"2"里面当然是没问题的"2",不过在外面其他地方就是"1"
作者: kiwatami (悠游自在)   2015-12-28 15:27:00
你的叙述听起来似乎是两个不同的ArrayList?会不会是这个 Library 复制了你的 ArrayList 才操作?
作者: jknm0510a (Kang)   2015-12-28 15:33:00
对耶,你里面写m"Le"Devices1,不一样????
楼主: freedom74569   2015-12-28 15:59:00
不好意思~没改好是一样的
作者: givemepass (λ)   2015-12-28 22:40:00
bluetoothDeviceListBeenRenewed我猜应该是一个callback 如果是 你拿不到值是正常的
作者: KeySabre (KeySabreur)   2015-12-28 23:48:00
onCreate时list还没被callback设值吧? 能否再叙述清楚一点呢
作者: bear0221 (小小黑)   2015-12-29 08:43:00
试着在callback时再去set adapter callback未回前先用pr

Links booklink

Contact Us: admin [ a t ] ucptt.com