Mad 9-10
Mad 9-10
Mad 9-10
</LinearLayout>
Activity_edit.xml
<?xml version="1.0" encoding="utf-8"?>
<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=".Edit" android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Course Registation"
android:textSize="30dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ID"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" android:ems="10"
android:id="@+id/id"
android:textAlignment="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" android:ems="10"
android:id="@+id/name"
android:textAlignment="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Course"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" android:ems="10"
android:id="@+id/course"
android:textAlignment="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fee"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:id="@+id/fee"
android:textAlignment="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/bt1"
android:text="Edit"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/bt2"
android:text="Delete"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" android:id="@+id/bt3"
android:text="Back"
/>
</LinearLayout>
</LinearLayout>
Activity_view.xml
<?xml version="1.0" encoding="utf-8"?>
<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=".view"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lst1" />
</LinearLayout>
Activity_main.java
package com.example.sqlite;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText ed1,ed2,ed3;
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1 = findViewById(R.id.name);
ed2 = findViewById(R.id.course);
ed3 = findViewById(R.id.fee);
b1 = findViewById(R.id.bt1);
b2 = findViewById(R.id.bt2);
b2.setOnClickListener(new View.OnClickListener()
{@Override
public void onClick(View v)
{
Intent i = new Intent(getApplicationContext(),view.class);
startActivity(i);
}
});
b1.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View v) {
insert();
}
});
}
public void insert()
{
try
{
String name = ed1.getText().toString();
String course = ed2.getText().toString();
String fee = ed3.getText().toString();
SQLiteDatabase db = openOrCreateDatabase("SliteDb",
Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS records(id INTEGER PRIMARY KEY
AUTOINCREMENT,name VARCHAR,course VARCHAR,fee VARCHAR)");
String sql = "insert into records(name,course,fee)values('" +name + "','" + course +
"','" + fee + "')";
SQLiteStatement statement = db.compileStatement(sql);
statement.execute();
Toast.makeText(this,"Record addded",Toast.LENGTH_LONG).show();
ed1.setText("");
ed2.setText("");
ed3.setText("");
ed1.requestFocus();
}
catch (Exception ex)
{
Toast.makeText(this,"RecordFail",Toast.LENGTH_LONG).show();
}
}
}
Activity_edit.java
package com.example.sqlite;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Edit extends AppCompatActivity {
EditText ed1,ed2,ed3,ed4;
Button b1,b2,b3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit);
ed1 = findViewById(R.id.name);
ed2 = findViewById(R.id.course);
ed3 = findViewById(R.id.fee);
ed4 = findViewById(R.id.id);
b1 = findViewById(R.id.bt1);
b2 = findViewById(R.id.bt2);
b3 = findViewById(R.id.bt3);
Intent i = getIntent();
String t1 = i.getStringExtra("id").toString();
String t2 = i.getStringExtra("name").toString();
String t3 = i.getStringExtra("course").toString();
String t4 = i.getStringExtra("fee").toString();
ed4.setText(t1);
ed1.setText(t2);
ed2.setText(t3);
ed3.setText(t4);
b2.setOnClickListener(new View.OnClickListener()
{@Override
public void onClick(View v) {
try
{
String id = ed4.getText().toString();SQLiteDatabase db =
openOrCreateDatabase("SliteDb",Context.MODE_PRIVATE,null);
String sql = "delete from records where id = " + id + "";
SQLiteStatement statement = db.compileStatement(sql);
statement.execute();
Toast.makeText(Edit.this,"RecordDeleted",Toast.LENGTH_LONG).show();
ed1.setText("");
ed2.setText("");
ed3.setText("");
ed1.requestFocus();
}
catch (Exception ex)
{
Toast.makeText(Edit.this,"Record Fail",Toast.LENGTH_LONG).show();
}
}
});
b3.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),view.class);
startActivity(i);
}
});
b1.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View v) {
try {
String name = ed1.getText().toString();
String course = ed2.getText().toString();
String fee = ed3.getText().toString();
String id = ed4.getText().toString();
SQLiteDatabase db = openOrCreateDatabase("SliteDb",Context.MODE_PRIVATE,
null);
String sql = "update records set name = '" + name + "',course='" +course +
"',fee='" + fee + "' where id= " + id + "";
SQLiteStatement statement = db.compileStatement(sql);
statement.execute();
Toast.makeText(Edit.this, "Record Updated",
Toast.LENGTH_LONG).show();
ed1.setText("");
ed2.setText("");
ed3.setText("");
ed1.requestFocus();
} catch (Exception ex) {
Toast.makeText(Edit.this, "Record Fail", Toast.LENGTH_LONG).show();
}
}
});
}}
Activity_view.java
package com.example.sqlite;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
public class view extends AppCompatActivity {
ListView lst1;
ArrayList<String> titles = new ArrayList<String>();
ArrayAdapter arrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
SQLiteDatabase db = openOrCreateDatabase("SliteDb",Context.MODE_PRIVATE,null);
lst1 = findViewById(R.id.lst1);
final Cursor c = db.rawQuery("select * from records",null);
int id = c.getColumnIndex("id");
int name = c.getColumnIndex("name");
int course = c.getColumnIndex("course");
int fee = c.getColumnIndex("fee");
titles.clear();
arrayAdapter = new ArrayAdapter(this,
androidx.appcompat.R.layout.support_simple_spinner_dropdown_item,titles);
lst1.setAdapter(arrayAdapter);
final ArrayList<Student> stud = new ArrayList<Student>();
if(c.moveToFirst())
{
do {
Student stu = new Student();
stu.id = c.getString(id);
stu.name = c.getString(name);
stu.course = c.getString(course);
stu.fee = c.getString(fee);
stud.add(stu);
titles.add(c.getString(id) + " \t " + c.getString(name) + "\t " + c.getString(course) + "
\t " + c.getString(fee) );
} while(c.moveToNext());
arrayAdapter.notifyDataSetChanged();
lst1.invalidateViews();
}
lst1.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
Student stu = new Student();
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
String aa = titles.get(position).toString();
Student tstu = stud.get(position);
Intent i = new Intent(getApplicationContext(),Edit.class);
i.putExtra("id",stu.id);
i.putExtra("name",stu.name);
i.putExtra("course",stu.course);
i.putExtra("fee",stu.fee);
startActivity(i);
}
});
}
}
Student.java
package com.example.sqlite;
MainActivity.java
package com.example.sms;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.Manifest;
import androidx.appcompat.app.AppCompatActivity;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextPhoneNumber = findViewById(R.id.editTextPhoneNumber);
editTextMessage = findViewById(R.id.editTextMessage);
textViewReceivedMessages = findViewById(R.id.textViewReceivedMessages);
if (!checkSMSPermission())
{
requestSMSPermission();
intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(smsReceiver, intentFilter);
@Override
super.onDestroy();
unregisterReceiver(smsReceiver);
if (phoneNumber.isEmpty())
return;
try {
catch (IllegalArgumentException e)
} catch (Exception e) {
String[]{Manifest.permission.SEND_SMS}, SMS_PERMISSION_CODE);
{ @Override
if (bundle != null)
if (pdus != null) {
};