#SQLite Database
Lightweight Open Source Database built-inside android OS.
SQLite is an RDBMS which is used for Store Structured data
#Demo Application

###STEP 1
Create the UI as mentioned above in activity_mail.xml
Inflate all the Views in Java (MainActivity.java) and set the corresponding onClick Listeners for the Buttons
Create a new Class as mentioned in STEP 2 and declare an Object for the new Class within (MainActivity.java)
Write the Insert logic within btnSave Button (calling the insertData() method which is defined in STEP 2)
boolean isInserted = myDB.insertData(edtName.getText().toString(),edtRole.getText().toString(),Integer.parseInt(edtRating.getText().toString()));
if(isInserted == true){
Toast.makeText(getApplicationContext(),"Data Inserted!",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(),"Data not Inserted!",Toast.LENGTH_LONG).show();
}
###STEP 2
Create a Separate Class "DatabaseHelper" extends SQLiteOpenHelper where the following is performed,
- Class Constructor - Creates the Database
- onCreate() is called for the first time and it creates the table
- onUpgrade() is called when there is a change in database version
- CustomMethods() like insertData() - Takes the Input values and Inserts the Value using ContentValues
package sqlitedatabasedemo.santhoshthepro.com.sqlitedatabasedemo;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by santhosh1 on 9/11/16.
*/
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "Employee.db";
public static final String TABLE_NAME = "employee_table";
public static final String COL_1 ="ID";
public static final String COL_2 = "NAME";
public static final String COL_3 = "ROLE";
public static final String COL_4 = "RATING";
public DatabaseHelper(Context context){
super(context,DATABASE_NAME,null,1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE "+ TABLE_NAME + "(ID INTEGER PRIMARY_KEY AUTOINCREMENT, NAME TEXT, ROLE TEXT, RATING INTEGER)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+ TABLE_NAME);
onCreate(db);
}
public boolean insertData(String name, String role, int rating){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentvalues = new ContentValues();
contentvalues.put(COL_2,name);
contentvalues.put(COL_3,role);
contentvalues.put(COL_4,rating);
long result = db.insert(TABLE_NAME,null,contentvalues);
if(result == -1){
return false;
}else{
return true;
}
}
}
Please follow the instruction here to solve and understand HAXM Error.
http://stackoverflow.com/questions/26355645/error-in-launching-avd