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

楼主: jknm0510a (Kang)   2015-12-28 15:30:52
※ 引述《freedom74569 (莫急莫慌莫害怕)》之铭言:
: 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;
: 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里作就可以了
作者: freedom74569   2015-12-28 21:17:00
感谢j大大,我有试着用UiThread做看看,不过还是没有成功,我在试看看,感谢有给我一个方向,不然无头苍蝇一样:)

Links booklink

Contact Us: admin [ a t ] ucptt.com