0% found this document useful (0 votes)
96 views

2

SQLite is an embedded SQL database available in Android that allows storing and managing data on the device. The document explains how to create an SQLite database and design a data entry form in Android. It involves adding necessary permissions, designing the activity layout with edittext and button widgets, creating a DBHandler class to perform SQLite operations like creating a table, and inserting data into the database. When the add button is clicked, the onClick method will insert the entered course details into the database table.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

2

SQLite is an embedded SQL database available in Android that allows storing and managing data on the device. The document explains how to create an SQLite database and design a data entry form in Android. It involves adding necessary permissions, designing the activity layout with edittext and button widgets, creating a DBHandler class to perform SQLite operations like creating a table, and inserting data into the database. When the add button is clicked, the onClick method will insert the entered course details into the database table.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

1. What is Layout? List out different layouts supported by android Systems.

Explain relative layout

2. Explain working with Telephony Manager

3. Demonstrate the use of array adapter and spinner control with code.

4. Explain Sqlite database and design a form with Course name, Course description, course
duration fields.
5. Create Android application for addition of any two numerical digits.(XML file and Java file

6 Design an Image switcher application?

7 Explain about commonly used layouts and controls with syntax?

8 Develop android app to select date and time in one application?

9 Explain Sqlite database and design data entry form

10 Write about accessing the telephony services using Telephony Manager


Refer pg no 553
1 Which of the following is not an fragment lifecycle call-back method?

A)onStat B)onpause C)onCreate D)onBackPressed

2 Which of the following is not a valid Android resource file name?

A)mylayout.xml B)myLayout.xml C)my_layout.xml D)mylayout1.xml

3 What is the name of the folder that contains the R.java file?

A)src B)res C)bin D)gen

4 What is the parent class of all Activity widgets?

A)ViewGroup B)Layout C)View D)Widget

5 ADB stands for __________________________________

A)Advance Debug Bridge B)Andorid Debug Bridge C)Android Dalvik


Bridge D)Advance Dalvik Bridge

6 Which of the following tools dumps system log messages including stack traces when the device or
emulator throws an error?

A)DDMS B)Logcat C)Console D)ADB

7 Which of the following methods updates a ListView when an element is added to the data set?

A)notify( ) B)notifyall( ) C)notifyDataSetChanged( ) D) notifyDataSetInvalidate( )


8 What are the main two types of thread in Android?

A)Main thread and worker threads. B) Main thread and UI thread.

C)Activities and services. D) Main thread and background process.

9 Which of the following methods is called in an Activity when another activity gets into the
foreground?

A)onPause() B)onDestroy() C)onStop() D)onExit

10 The DalvikVM core libraries are a subset of which of the following?

A)JAX-WS B)Java ME C) Java SE D) Java EE

11
______Types of layouts in android.
A) 7 B) 6 C) 3 D) 2

12
Layout or design of an android application is saved in

A) .text file B) .java file C) .dex file D).xml file

13
_________ allows you to select an item from a drop down menu.

A)Spinner B) CheckBox C) RadioButton D) ListView

14
_________Types of Orientations in android.

A) 5 B) 2 C) 3 D) 4

15
The ________________ is a debugging tool used in the Android platform.

A)JVM B) Compiler C) Android D)DDMS

16
If the menu items are less than or equal to six, the menu is called an______

A) Icon Menu B) Expanded Menu. C) Menu D) List Menu

17
Which of the following methods is called in an Activity when another activity gets into the
foreground?

A)onPause() B)onDestroy() C)onStop() D)onExit

18
_________ shows the process completion status in android.

A) Widget B) EditText C) Scroll View D) Progress bar

19
___________box is used for selecting a date by the user
A) DatePicker B) TimePicker C) Date class D) Calendar class

20
What is the name of the folder that contains the R.java file?

A)src B)res C)bin D)gen

21._____ ____method should you use to start a sub-activity.

22. Manifest file permission adds_____ ___ to allow your application to read the device’s address book.

23._____________________attributes is used to set an activity screen to landscape orientation.

24. A dialog is displayed on the screen using ______________ method.

25. _________________________adds zoom controls to a WebView?

26. ____________allows the user to flip left and right through pages of Data.

27. An AlertDialog box supports up to ______ no. of buttons

28. ___________are designed to use the device UI space efficiently


29.___________ xml file is used to add menu items in android application.

30. ___________method helps in knowing the ID of the selected menu item.

31. JavaScript is enabled by default in a Web View [ ]

32. Image file must be placed inside drawable folder [ ]

33. List View has a function to display a list of uniquely defined Views other than Text [ ]
View.
34. You can create a custom view by extending class Activity [ ]

35. Menu Item can display either an icon or text [ ]


Explain Sqlite database and design data entry form

SQLite is another data storage available in Android where we can store data in the user’s device and can
use it any time when required. In this article, we will take a look at creating an SQLite database in the
Android app and adding data to that database in the Android app. This is a series of 4 articles in which
we are going to perform the basic CRUD (Create, Read, Update, and Delete) operation with SQLite
Database in Android.

What is SQLite Database?

SQLite Database is an open-source database provided in Android which is used to store data inside the
user’s device in the form of a Text file. We can perform so many operations on this data such as adding
new data, updating, reading, and deleting this data. SQLite is an offline database that is locally stored in
the user’s device and we do not have to create any connection to connect to this database.

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android
Studio. Note that select Java as the programming language.

Step 2: Adding permissions to access the storage in the AndroidManifest.xml file

Navigate to the app > AndroidManifest.xml and add the below code to it.

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
/>

Step 3: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the
code for the activity_main.xml file.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"
android:orientation="vertical"

tools:context=".MainActivity">

<!--Edit text to enter course name-->

<EditText

android:id="@+id/idEdtCourseName"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="10dp"

android:hint="Enter course Name" />

<!--edit text to enter course duration-->

<EditText

android:id="@+id/idEdtCourseDuration"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="10dp"

android:hint="Enter Course Duration" />

<!--edit text to display course tracks-->

<EditText

android:id="@+id/idEdtCourseTracks"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="10dp"
android:hint="Enter Course Tracks" />

<!--edit text for course description-->

<EditText

android:id="@+id/idEdtCourseDescription"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="10dp"

android:hint="Enter Course Description" />

<!--button for adding new course-->

<Button

android:id="@+id/idBtnAddCourse"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="10dp"

android:text="Add Course"

android:textAllCaps="false" />

</LinearLayout>

Step 4: Creating a new Java class for performing


SQLite operations
import android.content.ContentValues;

import android.content.Context;

import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHandler extends SQLiteOpenHelper {

// creating a constant variables for our database.

// below variable is for our database name.

private static final String DB_NAME = "coursedb";

// below int is our database version

private static final int DB_VERSION = 1;

// below variable is for our table name.

private static final String TABLE_NAME = "mycourses";

// below variable is for our id column.

private static final String ID_COL = "id";

// below variable is for our course name column

private static final String NAME_COL = "name";

// below variable id for our course duration column.

private static final String DURATION_COL = "duration";

// below variable for our course description column.

private static final String DESCRIPTION_COL = "description";


// below variable is for our course tracks column.

private static final String TRACKS_COL = "tracks";

// creating a constructor for our database handler.

public DBHandler(Context context) {

super(context, DB_NAME, null, DB_VERSION);

// below method is for creating a database by running a sqlite query

@Override

public void onCreate(SQLiteDatabase db) {

// on below line we are creating

// an sqlite query and we are

// setting our column names

// along with their data types.

String query = "CREATE TABLE " + TABLE_NAME + " ("

+ ID_COL + " INTEGER PRIMARY KEY AUTOINCREMENT, "

+ NAME_COL + " TEXT,"

+ DURATION_COL + " TEXT,"

+ DESCRIPTION_COL + " TEXT,"

+ TRACKS_COL + " TEXT)";

// at last we are calling a exec sql

// method to execute above sql query


db.execSQL(query);

// this method is use to add new course to our sqlite database.

public void addNewCourse(String courseName, String courseDuration, String courseDescription,


String courseTracks) {

// on below line we are creating a variable for

// our sqlite database and calling writable method

// as we are writing data in our database.

SQLiteDatabase db = this.getWritableDatabase();

// on below line we are creating a

// variable for content values.

ContentValues values = new ContentValues();

// on below line we are passing all values

// along with its key and value pair.

values.put(NAME_COL, courseName);

values.put(DURATION_COL, courseDuration);

values.put(DESCRIPTION_COL, courseDescription);

values.put(TRACKS_COL, courseTracks);

// after adding all values we are passing

// content values to our table.

db.insert(TABLE_NAME, null, values);


// at last we are closing our

// database after adding database.

db.close();

@Override

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

// this method is called to check if the table exists already.

db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);

onCreate(db);

Step 5: Working with the MainActivity.java file


import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


// creating variables for our edittext, button and dbhandler

private EditText courseNameEdt, courseTracksEdt, courseDurationEdt, courseDescriptionEdt;

private Button addCourseBtn;

private DBHandler dbHandler;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// initializing all our variables.

courseNameEdt = findViewById(R.id.idEdtCourseName);

courseTracksEdt = findViewById(R.id.idEdtCourseTracks);

courseDurationEdt = findViewById(R.id.idEdtCourseDuration);

courseDescriptionEdt = findViewById(R.id.idEdtCourseDescription);

addCourseBtn = findViewById(R.id.idBtnAddCourse);

// creating a new dbhandler class

// and passing our context to it.

dbHandler = new DBHandler(MainActivity.this);

// below line is to add on click listener for our add course button.

addCourseBtn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {


// below line is to get data from all edit text fields.

String courseName = courseNameEdt.getText().toString();

String courseTracks = courseTracksEdt.getText().toString();

String courseDuration = courseDurationEdt.getText().toString();

String courseDescription = courseDescriptionEdt.getText().toString();

// validating if the text fields are empty or not.

if (courseName.isEmpty() && courseTracks.isEmpty() &&


courseDuration.isEmpty() && courseDescription.isEmpty()) {

Toast.makeText(MainActivity.this, "Please enter all the data..",


Toast.LENGTH_SHORT).show();

return;

// on below line we are calling a method to add new

// course to sqlite data and pass all our values to it.

dbHandler.addNewCourse(courseName, courseDuration,
courseDescription, courseTracks);

// after adding the data we are displaying a toast message.

Toast.makeText(MainActivity.this, "Course has been added.",


Toast.LENGTH_SHORT).show();

courseNameEdt.setText("");

courseDurationEdt.setText("");

courseTracksEdt.setText("");

courseDescriptionEdt.setText("");
}

});

You might also like