作者jknm0510a (Kang)
看板AndroidDev
标题Re: [问题] 有关於拿不到Arraylist的问题
时间Mon Dec 28 15:30:52 2015
※ 引述《freedom74569 (莫急莫慌莫害怕)》之铭言:
: https://webptt.com/cn.aspx?n=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;
: mLeDevices1.addAll(bluetoothList);
: // 这里打印的出来mDevices01,而且bluelist确定有东西也有打印出来
: Log.e("mDevices1", String.valueOf(mLeDevices1));
: }
: 我只有在这个function印得出来mDevices1,
: 不过在如onCreate or 其他地方要拿来用,
: 就拿不到mDevices1就为空的阵列
: 存不回去上面宣告的mDevices1那
: 我想问看看有什麽关键字!
: 现在完全没有方向...
activity 生命一开始没多久会call onCreate
我猜这时候你的bluetoothDeviceListBeenRenewed还没有被call到
因为你的list在bluetoothDeviceListBeenRenewed里面塞值的
在还没call的时候执行onCreate要找list的值当然是抓不到东西
这个假设的前提是onCreate比bluetoothDeviceListBeenRenewed先执行
如果list是要做UI相关的可以用handler回去UIThread作事
不然直接在bluetoothDeviceListBeenRenewed里作就可以了
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 59.120.183.130
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/AndroidDev/M.1451287855.A.A14.html
1F:推 freedom74569: 感谢j大大,我有试着用UiThread做看看,不过还是 12/28 21:17
2F:→ freedom74569: 没有成功,我在试看看,感谢有给我一个方向,不然 12/28 21:18
3F:→ freedom74569: 无头苍蝇一样:) 12/28 21:18