Questa community è dedicata esclusivamente allo sviluppo di applicazioni per Android.Se state cercando una guida su come rootare il vostro telefono,o su come installare l'ultima Cyanogen, avete sbagliato sito
package it.mp.foursmiles;import java.util.HashMap;import android.content.Context;import android.database.Cursor;import android.database.SQLException;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteOpenHelper;import android.util.Log;/** * Simple notes database access helper class. Defines the basic CRUD operations * for the notepad example, and gives the ability to list all notes as well as * retrieve or modify a specific note. * * This has been improved from the first version of this tutorial through the * addition of better error handling and also using returning a Cursor instead * of using a collection of inner classes (which is less scalable and not * recommended). */public class FourSmilesDbAdapter { public static final String KEY_OS_CODICE = "code"; public static final String KEY_OS_VALUE = "value"; public static final String KEY_OS_DIFFICULT = "KEY_DIFFICULT"; public static final String KEY_OS_OPPONENT = "KEY_OPPONENT"; public static final String KEY_OS_WARNING = "KEY_WARNING"; public static final String KEY_OS_IMAGE = "KEY_IMAGE"; public static final String KEY_OS_TYPE_GAME = "KEY_TYPE_GAME"; public static final int DIFFICULT_EASY = 1; public static final int DIFFICULT_MEDIUM = 2; public static final int DIFFICULT_HARD = 3; public static final int OPPONENT_COMPUTER = 0; public static final int OPPONENT_HUMAN = 1; public static final int WARNING_ON = 0; public static final int WARNING_OFF = 1; public static final int TYPE_GAME_NORMAL = 0; public static final int TYPE_GAME_ADVANCED = 1; public static final int IMAGE_SMILE = 0; public static final int IMAGE_CLASSIC = 1; private static final String TAG = "FourSmilesDbAdapter"; private DatabaseHelper mDbHelper; private SQLiteDatabase mDb; /** * Database creation sql statement */ private static final String DATABASE_NAME = "four_smiles"; private static final String DB_TABLE_OPTIONS = "four_options"; private static final String DATABASE_CREATE_OPTIONS = "create table "+DB_TABLE_OPTIONS+" ("+KEY_OS_CODICE+" text not null primary key, "+ KEY_OS_VALUE+" INTEGER not null);"; private static final int DATABASE_VERSION = 4; private final Context mCtx; private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } public void onCreate(SQLiteDatabase db) { try{ db.execSQL(DATABASE_CREATE_OPTIONS); db.execSQL("INSERT INTO " + DB_TABLE_OPTIONS + " VALUES (?, ?)", new Object[] {KEY_OS_DIFFICULT ,DIFFICULT_EASY } ); db.execSQL("INSERT INTO " + DB_TABLE_OPTIONS + " VALUES (?, ?)", new Object[] {KEY_OS_OPPONENT ,OPPONENT_HUMAN } ); db.execSQL("INSERT INTO " + DB_TABLE_OPTIONS + " VALUES (?, ?)", new Object[] {KEY_OS_WARNING ,WARNING_ON } ); db.execSQL("INSERT INTO " + DB_TABLE_OPTIONS + " VALUES (?, ?)", new Object[] {KEY_OS_IMAGE ,IMAGE_SMILE } ); db.execSQL("INSERT INTO " + DB_TABLE_OPTIONS + " VALUES (?, ?)", new Object[] {KEY_OS_TYPE_GAME ,TYPE_GAME_NORMAL } ); }catch(Exception ex){ ex.printStackTrace(); } } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS "+DB_TABLE_OPTIONS); onCreate(db); } } public FourSmilesDbAdapter(Context ctx) { this.mCtx = ctx; } public FourSmilesDbAdapter open() throws SQLException { mDbHelper = new DatabaseHelper(mCtx); mDb = mDbHelper.getWritableDatabase(); return this; } public void close() { mDbHelper.close(); mDb.close(); } public void updateOptions(String code,int value){ mDb.execSQL("UPDATE " + DB_TABLE_OPTIONS + " SET "+KEY_OS_VALUE+" = ? WHERE "+ KEY_OS_CODICE +" = ? ", new Object[] {value,code } ); } public HashMap<String,Integer> getHMOptions() { HashMap<String,Integer> hm=new HashMap<String,Integer>(); Cursor c= mDb.query(DB_TABLE_OPTIONS, new String[] {KEY_OS_CODICE, KEY_OS_VALUE}, null, null, null, null, null); while (c.moveToNext()){ hm.put(c.getString(0),c.getInt(1)); } if (!c.isClosed()){ c.close(); } return hm; }}
FourSmilesDbAdapter mDbHelper = new FourSmilesDbAdapter(this);mDbHelper.open(); HashMap<String,Integer> options = mDbHelper.getHMOptions();mDbHelper.close();