Finally, I received a response from this book.
Beginning.Android.Application.Development.
using SQLite I prepared the database, I get the row and display using TableLayout with TextView ..
this is the database adapter class
public class DBAdapter3x3 { public static final String KEY_ROWID = "_id"; public static final String KEY_NAME = "name"; public static final String KEY_MOVES = "moves"; public static final String KEY_TIME = "time"; private static final String TAG = "DBAdapter"; private static final String DATABASE_NAME = "SliderDB3x3.db"; private static final String DATABASE_TABLE = "topscore3x3"; private static final int DATABASE_VERSION = 1; private static final String DATABASE_CREATE = "create table topscore3x3 " + "(_id integer primary key autoincrement, " + "name text not null, moves integer not null," + "time text not null);"; private final Context context; private DatabaseHelper DBHelper; private SQLiteDatabase db; public DBAdapter3x3(Context ctx) { this.context = ctx; DBHelper = new DatabaseHelper(context); } private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { try { db.execSQL(DATABASE_CREATE); } catch (SQLException e) { e.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 contacts"); onCreate(db); } }
I used the database in this activity
public class TopScore3x3 extends Activity { private DBAdapter3x3 db; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.db3x3); db = new DBAdapter3x3(this); getall(); delete(); private void delete() { db.open(); Cursor c = db.SortAllRows(); int i=1; if (c.moveToFirst()) { do { if(i>10) { db.deleteContact(i); } i++; } while (c.moveToNext()); } c.close(); db.close(); } private void getall() {
source share