Professional Documents
Culture Documents
Ese Android U3 PDF
Ese Android U3 PDF
Code:-
activity_main.xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/a
pk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.kttpoint.com.kotlinsharedpreference.MainActivity">
<TableLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="10sp"
android:layout_marginStart="10sp"
android:text="Enter Id"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" />
<EditText
android:id="@+id/editId"
android:layout_width="201dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginLeft="50sp"
android:layout_marginStart="50sp"
android:hint="id"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="10sp"
android:layout_marginStart="10sp"
android:text="Enter Name"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Mediu
m" />
<EditText
android:id="@+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginLeft="50sp"
android:layout_marginStart="50sp"
android:hint="name"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Mediu
m" />
</TableRow>
<TableRow android:layout_marginTop="60dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="10sp"
android:layout_marginStart="10sp"
android:text="Your Id"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Mediu
m" />
<TextView
android:id="@+id/textViewShowId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginLeft="50sp"
android:layout_marginStart="50sp"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" />
</TableRow>
<TableRow android:layout_marginTop="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="10sp"
android:layout_marginStart="10sp"
android:text="Your Name"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" />
<TextView
android:id="@+id/textViewShowName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginLeft="50sp"
android:layout_marginStart="50sp"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Mediu
m" />
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:orientation="horizontal"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save" />
<Button
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View" />
<Button
android:id="@+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.kt
package example.kttpoint.com.kotlinsharedpreference
import android.content.Context
import android.content.SharedPreferences
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ntext.MODE_PRIVATE)
btnSave.setOnClickListener(View.OnClickListener {
editor.putInt("id_key",id)
editor.putString("name_key",name)
editor.apply()
editor.commit()
})
btnView.setOnClickListener {
}else{
outputName.setText(sharedNameValue).toString()
outputId.setText(sharedIdValue.toString())
btnClear.setOnClickListener(View.OnClickListener {
editor.clear()
editor.apply()
outputName.setText("").toString()
outputId.setText("".toString())
})
Screenshot:-
3.Write a Kotlin program in Android to demonstrate the use of External Storage
Code:-
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.kttpoint.com.kotlinexternalstoragereadwrite.MainActivity"
>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_alignParentTop="true"
android:layout_alignStart="@+id/textView2"
android:layout_marginTop="68dp"
android:text="File Name"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.027"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.065" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editTextData"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="36dp"
android:layout_marginLeft="50dp"
android:layout_marginStart="50dp"
android:text="File Data"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.027"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.167" />
<EditText
android:id="@+id/editTextFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editTextData"
android:layout_alignStart="@+id/editTextData"
android:layout_alignTop="@+id/textView"
android:ems="10"
android:inputType="none" />
<EditText
android:id="@+id/editTextData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/editTextFile"
android:layout_marginEnd="37dp"
android:layout_marginRight="37dp"
android:layout_marginTop="30dp"
android:ems="10"
android:inputType="none"
android:lines="5" />
<Button
android:id="@+id/button_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="68dp"
android:layout_toLeftOf="@+id/editTextData"
android:layout_toStartOf="@+id/editTextData"
android:text="Save" />
<Button
android:id="@+id/button_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button_save"
android:layout_alignEnd="@+id/editTextData"
android:layout_alignRight="@+id/editTextData"
android:layout_marginEnd="43dp"
android:layout_marginRight="43dp"
android:text="View" />
</RelativeLayout>
MainActivity.kt
package example.kttpoint.com.kotlinexternalstoragereadwrite
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import android.os.Environment
import java.io.*
return if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) {
true
} else {
false
return if (Environment.MEDIA_MOUNTED.equals(extStorageState)) {
true
} else{
false
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
saveButton.setOnClickListener(View.OnClickListener {
try {
fileOutPutStream.write(fileData.text.toString().toByteArray())
fileOutPutStream.close()
e.printStackTrace()
Toast.makeText(applicationContext,"data save",Toast.LENGTH_SHORT).show()
})
viewButton.setOnClickListener(View.OnClickListener {
myExternalFile = File(getExternalFilesDir(filepath),filename)
stringBuilder.append(text)
fileInputStream.close()
Toast.makeText(applicationContext,stringBuilder.toString(),Toast.LENGTH_S
HORT).show()
})
if (!isExternalStorageAvailable || isExternalStorageReadOnly) {
saveButton.isEnabled = false
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.kttpoint.com.kotlinexternalstoragereadwrite">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<usespermission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
Screenshot
4.Write a Kotlin program in Android to provide user(s) with 3 options of creating a Simple
Notification,
Custom Notification and Clear Notification. Implement appropriate functionality and perform the
required task
Code :-
activity_main.xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/a
pk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.kttpoint.com.androidnotification.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ANDROID NOTIFICATION"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.091"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_marginBottom="112dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Notify"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
activity_notification_view.xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/a
pk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.kttpoint.com.androidnotification.NotificationView">
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.096"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.206"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>
</android.support.constraint.ConstraintLayout>
MainActivity.kt
package example.kttpoint.com.androidnotification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Button button;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
addNotification();
});
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
essage
otification
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
nt,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
// Add as notification
ICATION_SERVICE);
manager.notify(0, builder.build());
NotificationView.kt
package example.kttpoint.com.androidnotification;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification_view);
textView = findViewById(R.id.textView);
String message=getIntent().getStringExtra("message");
textView.setText(message);
strings.xml
<resources>
<string name="app_name">AndroidNotification</string>
<string name="notification_activity">NotificationView</string>
</resources>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.kttpoint.com.androidnotification">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
</intent-filter>
</activity>
<activity android:name=".NotificationView"
android:label="@string/notification_activity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
</application>
</manifest>
Screenshot :-
6.Write a Kotlin program in Android to implement the Telephony API to send SMS
Code:-
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/fstTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="150dp"
<EditText
android:id="@+id/mblTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:ems="10"/>
<TextView
android:id="@+id/secTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:layout_marginLeft="100dp" />
<EditText
android:id="@+id/msgTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:ems="10" />
<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
</LinearLayout>
MainActivity.kt
package com.tutlane.sendsmsexample;
import android.content.Intent;
import android.net.Uri;
import android.provider.Telephony;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtMobile = (EditText)findViewById(R.id.mblTxt);
txtMessage = (EditText)findViewById(R.id.msgTxt);
btnSms = (Button)findViewById(R.id.btnSend);
btnSms.setOnClickListener(new View.OnClickListener() {
@Override
smgr.sendTextMessage(txtMobile.getText().toString(),nul
l,txtMessage.getText().toString(),null,null);
y", Toast.LENGTH_SHORT).show();
});
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tutlane.sendsmsexample">
<uses-permission android:name="android.permission.SEND_SMS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" /
>
</intent-filter>
</activity>
</application>
</manifest>
Screenshot
7. Create a database “FriendsDB” to store information about your friends. Implement CRUD
functionality
Code :-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<EditText
android:id="@+id/student_id"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:inputType="number"
android:hint="Student ID"
/>
<EditText
android:id="@+id/student_name"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:hint="Student Name"
/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="loadStudents"
/>
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Result"
android:textSize="30dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="addStudent"
android:text="ADD" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="updateStudent"
android:text="UPDATE"
/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="deleteStudent"
android:text="DELETE By Id"
/>
</LinearLayout>
MyDBHandler(Context context)
{
@Override
+ COLUMN_NAME
db.execSQL(CREATE_STUDENT_TABLE);
table.
String loadHandler() {
SQLiteDatabase db = this.getWritableDatabase();
while (cursor.moveToNext()) {
System.getProperty("line.separator");
cursor.close();
db.close();
if(result.equals(""))
long id;
values.put(COLUMN_ID, student.getID());
values.put(COLUMN_NAME, student.getStudentName());
SQLiteDatabase db = this.getWritableDatabase();
db.close();
return id;
SQLiteDatabase db = this.getWritableDatabase();
args.put(COLUMN_ID, ID);
args.put(COLUMN_NAME, name);
String query = "Select*FROM " + TABLE_STUDENTS + " WHERE " + COLUMN_ID + " = '" +
String.valueOf(ID) + "'";
SQLiteDatabase db = this.getWritableDatabase();
if (cursor.moveToFirst()) {
student.setID(Integer.parseInt(cursor.getString(0)));
new String[] {
String.valueOf(student.getID())
});
cursor.close();
result = true;
db.close();
return result;
resultText.setText(dbHandler.loadHandler());
studentId.setText("");
studentName.setText("");
int id = Integer.parseInt(studentId.getText().toString());
long insertId=dbHandler.addHandler(student);
if(insertId==-1){
else{
studentId.setText("");
studentName.setText("");
resultText.setText("Record added");
}
else{
studentId.getText().toString()), studentName.getText().toString());
if (result) {
studentId.setText("");
studentName.setText("");
resultText.setText("Record Updated");
} else {
else{
if(!studentId.getText().toString().isEmpty()) {
studentId.getText().toString()));
if (result) {
studentId.setText("");
studentName.setText("");
resultText.setText("Record Deleted");
} else {
}
} else{
Whole Code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<EditText
android:id="@+id/student_id"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:inputType="number"
android:hint="Student ID"
/>
<EditText
android:id="@+id/student_name"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:hint="Student Name"
/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="loadStudents"
/>
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Result"
android:textSize="30dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="addStudent"
android:text="ADD" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="updateStudent"
android:text="UPDATE"
/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="deleteStudent"
android:text="DELETE By Id"
/>
</LinearLayout>
MainActivity.kt
package com.programtown.example;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
TextView resultText;
EditText studentId;
EditText studentName;
MyDBHandler dbHandler;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultText.setMovementMethod(new ScrollingMovementMethod());
studentId.setText("");
studentName.setText("");
int id = Integer.parseInt(studentId.getText().toString());
long insertId=dbHandler.addHandler(student);
if(insertId==-1){
else{
studentId.setText("");
studentName.setText("");
resultText.setText("Record added");
else{
studentId.getText().toString()), studentName.getText().toString());
if (result) {
studentId.setText("");
studentName.setText("");
resultText.setText("Record Updated");
} else {
else{
if(!studentId.getText().toString().isEmpty()) {
studentId.getText().toString()));
if (result) {
studentId.setText("");
studentName.setText("");
resultText.setText("Record Deleted");
} else {
} else{
@Override
super.onDestroy();
dbHandler.close();
MyDBHandler.kt
package com.programtown.example;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
MyDBHandler(Context context)
@Override
db.execSQL(CREATE_STUDENT_TABLE);
@Override
int newVersion) {
onCreate(db);
String loadHandler() {
while (cursor.moveToNext()) {
System.getProperty("line.separator");
cursor.close();
db.close();
if(result.equals(""))
return result;
long id;
values.put(COLUMN_ID, student.getID());
values.put(COLUMN_NAME, student.getStudentName());
SQLiteDatabase db = this.getWritableDatabase();
db.close();
return id;
SQLiteDatabase db = this.getWritableDatabase();
args.put(COLUMN_ID, ID);
args.put(COLUMN_NAME, name);
}
boolean deleteHandler(int ID) {
String query = "Select*FROM " + TABLE_STUDENTS + " WHERE " + COLUMN_ID + " = '" +
String.valueOf(ID) + "'";
SQLiteDatabase db = this.getWritableDatabase();
if (cursor.moveToFirst()) {
student.setID(Integer.parseInt(cursor.getString(0)));
new String[] {
String.valueOf(student.getID())
});
cursor.close();
result = true;
db.close();
return result;
Student.kt
package com.programtown.example;
Student() {
this.id = id;
this.studentName = studentName;
}
void setID(int id) {
this.id = id;
int getID() {
return this.id;
this.studentName = studentname;
String getStudentName() {
return this.studentName;
OUTPUT