SQLite
创建数据库
final SQLiteDatabase db = openOrCreateDatabase("graphicsCard", Context.MODE_PRIVATE,null);
String create = "create table if not exists graphicsCard(id integer primary key autoincrement,name text not null,price integer not null);";
db.execSQL(create);
增加数据
final ContentValues in = new ContentValues();
in.put("name", "GTX1080 ti");
in.put("price", 8299);
db.insert("graphicsCard", null, in);
in.put("name", "GTX1080");
in.put("price", 4799);
db.insert("graphicsCard", null, in);
id |
name |
price |
1 |
GTX1080 ti |
8299 |
2 |
GTX1080 |
4799 |
查
int price = Integer.parseInt(et_search.getText()+"");
String search = "select * from graphicsCard where price = "+price;
Cursor cursor = db.rawQuery(search,null);
String str = null;
if(cursor.moveToNext()){
str = cursor.getString(cursor.getColumnIndex("id"))+" "
+cursor.getString(cursor.getColumnIndex("name"))+" "
+cursor.getInt(cursor.getColumnIndex("price"));
}
cursor.close();
关闭
db.close();
SharedPreferences
创建
SharedPreferences sp;
sp = getSharedPreferences("save", Activity.MODE_PRIVATE);
boolean isFirst = sp.getBoolean("save",true);
置
SharedPreferences.Editor editor = sp.edit();
isFirst = false;
editor.putBoolean("save",isFirst);
editor.commit();