//停車場數(shù)據(jù)導(dǎo)入
public?void?initParkingLot()?{
????parkingLotList.clear();//先清空list內(nèi)數(shù)據(jù)
????mThread?=?new?MyThread();
????mThread.start();
????mHandler?=?new?Handler()?{
????????public?void?handleMessage(Message?msg)?{
????????????super.handleMessage(msg);
????????????switch?(msg.what)?{
????????????????case?1://msg的what判斷是哪個bundle的請求
????????????????????//創(chuàng)建停車場實例
????????????????????parkingLotList.add(new?ParkingLot(msg.getData().getInt("ID"),?msg.getData().getString("state"),
????????????????????????????msg.getData().getString("name"),?msg.getData().getDouble("latitude"),
????????????????????????????msg.getData().getDouble("longitude"),?msg.getData().getInt("sum"),
????????????????????????????msg.getData().getInt("yt"),?msg.getData().getInt("kt"),?msg.getData().getDouble("price"),
????????????????????????????msg.getData().getDouble("level")));
????????????????????//測算出每個停車場距離目前的距離,動態(tài)更新ParkingLot的distance成員
????????????????????LatLng?curLatLng?=?new?LatLng(curLatitude,?curLongitude);
????????????????????LatLng?desLatLng?=?new?LatLng(parkingLotList.get(parkingLotList.size()?-?1).getLatitude(),
????????????????????????????parkingLotList.get(parkingLotList.size()?-?1).getLongitude());
????????????????????//調(diào)用距離測算函數(shù)(修改整個List中剛加進(jìn)來的對象的distance屬性)
????????????????????parkingLotList.get(parkingLotList.size()?-?1).distance?=
????????????????????????????(int)?AMapUtils.calculateLineDistance(curLatLng,?desLatLng);
????????????????????//排序
????????????????????Collections.sort(parkingLotList);
????????????????????//適配器的設(shè)置
????????????????????ParkingLotAdapter?adapter?=?new?ParkingLotAdapter(
????????????????????????????ParkActivity.this,?R.layout.parkinglot_item,?parkingLotList);
????????????????????ListView?listView?=?(ListView)?findViewById(R.id.list_view);
????????????????????listView.setAdapter(adapter);
????????????????????//測試,輸出size
????????????????????System.out.println(parkingLotList.size());
????????????????????break;
????????????????default:
????????????????????break;
????????????}
????????}
????};
}這段代碼是將數(shù)據(jù)庫的停車場數(shù)據(jù)導(dǎo)入parkingLotList(List類型)中,然而是同伴寫的代碼,我也不太懂這兩個線程啥關(guān)系,執(zhí)行完這個函數(shù)以后,parkingLotList的size竟然是0!這是為什么!而且在這個函數(shù)中測試的時候size是對的,不知道為什么執(zhí)行完函數(shù)以后size就變成0了!求懂的人解答??!T T?。。?!
Android中線程的問題!很急T T
NLPLearner
2018-03-17 16:50:17