Android 数据库与MapView总结
2010-11-05 00:54:34 来源:WEB开发网/* 系统选择餐馆 */
drawRestaurant();
}
private void drawRestaurant() {
String f[] = { "f_id", "f_name", "f_address", "f_cal"};
/* SELECT f[] FROM tables[0] */
Cursor c = dbHelper.select
(
tables[0], f, "", null, null, null, null
);
allRestaurantID = new ArrayList();
allRestaurantName = new ArrayList();
allRestaurantAddress = new ArrayList();
allRestaurantCal = new ArrayList();
/* 将所有餐厅数据放入List对象 */
while (c.moveToNext())
{
allRestaurantID.add(c.getString(0));
allRestaurantName.add(c.getString(1));
allRestaurantAddress.add(c.getString(2));
allRestaurantCal.add(c.getString(3));
}
if(allRestaurantID.size()>0)
{
Random generator = new Random();
int intThrowIndex = generator.nextInt(allRestaurantID.size());
mTextView01.setText
(
allRestaurantName.get(intThrowIndex)+" "+
allRestaurantAddress.get(intThrowIndex)+" "+
allRestaurantCal.get(intThrowIndex)+
getResources().getText(R.string.str_cal)
);
/* 以地址查询地理坐标 */
GeoPoint gp =
getGeoByAddress(allRestaurantAddress.get(intThrowIndex));
if(gp==null)
{
/* 地址无法反查为GeoPoint时 */
mMapView01.setVisibility(MapView.GONE);
}
else
{
/* 更新MapView地图 */
mMapView01.setVisibility(MapView.VISIBLE);
showImageOverlay(gp);
refreshMapViewByGeoPoint
(
getGeoByAddress(allRestaurantAddress.get(intThrowIndex)),
mMapView01, intZoomLevel, true
);
}
}
else
{
/* 数据库无记录 */
更多精彩
赞助商链接