WEB开发网
开发学院手机开发Android 开发 Android 数据库与MapView总结 阅读

Android 数据库与MapView总结

 2010-11-05 00:54:34 来源:WEB开发网   
核心提示:String tables[] = { "t_restaurant" };String fieldNames[][] = { { "f_id", "f_name", "f_address", "f_cal" } };St

String tables[] = { "t_restaurant" };

String fieldNames[][] = { { "f_id", "f_name", "f_address", "f_cal" } };

String fieldTypes[][] = { { "INTEGER PRIMARY KEY AUTOINCREMENT", "text",

"text", "text" } };

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.layout_add);

mEditText01 = (EditText) findViewById(R.id.myEditText1);

mEditText02 = (EditText) findViewById(R.id.myEditText2);

mEditText03 = (EditText) findViewById(R.id.myEditText3);

dbHelper = new MySQLiteOpenHelper(this, "mydb", null, version, tables,

fieldNames, fieldTypes);

mButton01 = (Button) findViewById(R.id.myButton1);

mButton01.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {

if (mEditText01.getText().toString().trim().length() != 0

&& mEditText02.getText().toString().trim().length() != 0

&& mEditText03.getText().toString().trim().length() != 0) {

String f[] = { "f_id", "f_name" };

String[] selectionArgs = { mEditText01.getText().toString() };

Cursor c = dbHelper.select(tables[0], f, "f_name=?",

selectionArgs, null, null, null);

String strRes = "";

while (c.moveToNext()) {

strRes += c.getString(0) + " ";

}

if (strRes == "") {

String f2[] = { "f_name", "f_address", "f_cal" };

String v[] = { mEditText01.getText().toString().trim(),

mEditText02.getText().toString().trim(),

mEditText03.getText().toString().trim()

};

long rowid = dbHelper.insert(tables[0], f2, v);

strRes += rowid + " ";

} else {

}

if (dbHelper != null

&& dbHelper.getReadableDatabase().isOpen()) {

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:Android 数据库 MapView

编辑录入:coldstar [复制链接] [打 印]
赞助商链接