Android 数据库与MapView总结
2010-11-05 00:54:34 来源:WEB开发网private MySQLiteOpenHelper dbHelper=null;
private int version = 1;
private List allRestaurantID;
private List allRestaurantName;
private List allRestaurantAddress;
private List allRestaurantCal;
/* 数据库数据表 */
private String tables[] = { "t_restaurant" };
/* 数据库字段名称 */
private String fieldNames[][] =
{
{ "f_id", "f_name", "f_address", "f_cal" }
};
/* 数据库字段数据类型 */
private String fieldTypes[][] =
{
{ "INTEGER PRIMARY KEY AUTOINCREMENT", "text" , "text", "text"}
};
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_draw);
mTextView01 = (TextView)findViewById(R.id.myTextView7);
/* 创建MapView对象 */
mMapView01 = (MapView)findViewById(R.id.myMapView1);
/* 数据库连接 */
dbHelper = new MySQLiteOpenHelper
(this, "mydb", null, version, tables, fieldNames, fieldTypes);
/* 系统选择餐馆 */
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));
更多精彩
赞助商链接