uestion OnePg. 01
uestion One
“There is an issue of exactly how the results we get back from our queries are
formatted”, Explain this in terms of the Database Cursor in Android with a coding
example of your own.
Answer:
Question Two
Pg. 02
Question Two
Give reasons why React should be preferred over the other frameworks, like
Angular, or any other (of your choice)?
(The student might compare with any framework of his choice)
Answer:
Question Three
Pg. 03
Question Three
Use the incomplete code to implement a simple mobile application that is
connected to the database and performs three operations insert, delete, and
view all the data as follows:
Copy and paste the following XML script in the activity_main.xml
activity_main.xml:
Question Three
Pg. 05
Then move to MainActivity.java and paste the following java code:
MainActivity.java:
package com.example.q3; //Modify q3 to your project name
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
//Create variables for EditText and Button.
//Create Database reference
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initialize all the variables.
// Implementation of insertion to the Database
// Implementation of deleting a record from the Database.
Question Three
Pg. 06
// Implementation if display all the data from the Database
//Display the data to user
StringBuilder buffer = new StringBuilder();
while (.moveToNext()) //add the cursor object
{
buffer.append(“name “).append( .getString(0)).append(“\n”); //add the cursor
object
buffer.append(“contact “).append( .getString(1)).append(“\n\n”); //add the
cursor object
}
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setCancelable(true);
builder.setTitle(“user Information”);
builder.setMessage(buffer.toString());
builder.show();
});
}
}
Question Three
Pg. 07
Then, create a java class, name it DBManager.java and paste the following java code.
DBManager.java:
package com.example.q3; //Modify q3 to your project name
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
public class DBManager extends SQLiteOpenHelper {
private static final String DB_NAME = “userdata”;
private static final String Table_Name = “userdetails”;
private static final String Table_Ncol = “name”;
private static final int DB_VErsion = 1;
private SQLiteDatabase db;
public DBManager(@Nullable Context context) {
super(context, DB_NAME, null, DB_VErsion);
}
@Override
public void onCreate(SQLiteDatabase DB) {
DB.execSQL(“create table Table_Name (name TEXT primary key, contact TEXT)”);
}
@Override
public void onUpgrade(SQLiteDatabase DB, int i, int i1) {
DB.execSQL(“drop table if exists Table_Name”);
}
// Implementation of saveuserdata method
// Implementation of deletedata method
// Implementation of selectAll method
}
Question Three
Pg. 08
You need to add the code below the comments in both files, MainActivity.java and
DBManager.java.
In the MainActivity.java, you need to add the following code:
1. Create variables for EditText and Button.
2. Create Database reference.
3. Initialize all the variables.
4. Implementation of insertion to the Database.
5. Implementation of deleting a record from the Database.
6. Implementation of display of all the data from the Database.
In the DBManager.java, you need to add the following code:
1. Implementation of saveuserdata method.
2. Implementation of the deletedata method.
3. Implementation of the selectAll method.