Android 数据库与MapView总结
2010-11-05 00:54:34 来源:WEB开发网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()) {
更多精彩
赞助商链接