activity_main.
xml
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<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:textColor="@color/colorAccent"
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="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="Ok"
android:background="@color/colorPrimary"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/bt2"
android:text="View"
android:background="@color/colorAccent"
/>
</LinearLayout>
</LinearLayout>
[Link]
public class MainActivity extends AppCompatActivity {
EditText ed1,ed2,ed3;
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
ed1 = findViewById([Link]);
ed2 = findViewById([Link]);
ed3 = findViewById([Link]);
b1 = findViewById([Link].bt1);
b2 = findViewById([Link].bt2);
[Link](new [Link]() {
@Override
public void onClick(View v)
{
Intent i = new Intent(getApplicationContext(),[Link]);
startActivity(i);
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
insert();
}
});
}
public void insert()
{
try
{
String name = [Link]().toString();
String course = [Link]().toString();
String fee = [Link]().toString();
SQLiteDatabase db =
openOrCreateDatabase("SliteDb",Context.MODE_PRIVATE,null);
[Link]("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(?,?,?)";
SQLiteStatement statement = [Link](sql);
[Link](1,name);
[Link](2,course);
[Link](3,fee);
[Link]();
[Link](this,"Record addded",Toast.LENGTH_LONG).show();
[Link]("");
[Link]("");
[Link]("");
[Link]();
}
catch (Exception ex)
{
[Link](this,"Record Fail",Toast.LENGTH_LONG).show();
}
}
}
activity_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".view">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lst1"
/>
</LinearLayout>
Create a Student Class
package [Link];
public class student {
String id;
String name;
String course;
String fee;
String titles;
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class view extends AppCompatActivity {
ListView lst1;
ArrayList<String> titles = new ArrayList<String>();
ArrayAdapter arrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_view);
SQLiteDatabase db = openOrCreateDatabase("SliteDb",Context.MODE_PRIVATE,null);
lst1 = findViewById([Link].lst1);
final Cursor c = [Link]("select * from records",null);
int id = [Link]("id");
int name = [Link]("name");
int course = [Link]("course");
int fee = [Link]("fee");
[Link]();
arrayAdapter = new
ArrayAdapter(this,[Link].support_simple_spinner_dropdown_item,titles);
[Link](arrayAdapter);
final ArrayList<student> stud = new ArrayList<student>();
if([Link]())
{
do{
student stu = new student();
[Link] = [Link](id);
[Link] = [Link](name);
[Link] = [Link](course);
[Link] = [Link](fee);
[Link](stu);
[Link]([Link](id) + " \t " + [Link](name) + " \t " + [Link](course) + "
\t " + [Link](fee) );
} while([Link]());
[Link]();
[Link]();
[Link](new [Link]() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String aa = [Link](position).toString();
student stu = [Link](position);
Intent i = new Intent(getApplicationContext(),[Link]);
[Link]("id",[Link]);
[Link]("name",[Link]);
[Link]("course",[Link]);
[Link]("fee",[Link]);
startActivity(i);
}
});
}
}
activity_edit.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".edit"
android:orientation="vertical"
android:gravity="center"
>
<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:textColor="@color/colorAccent"
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"
android:background="@color/colorPrimary"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/bt2"
android:text="Delete"
android:background="@color/colorAccent"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/bt3"
android:text="Back"
android:background="@color/colorPrimaryDark"
/>
</LinearLayout>
</LinearLayout>
[Link]
public class edit extends AppCompatActivity {
EditText ed1,ed2,ed3,ed4;
Button b1,b2,b3;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_edit);
ed1 = findViewById([Link]);
ed2 = findViewById([Link]);
ed3 = findViewById([Link]);
ed4 = findViewById([Link]);
b1 = findViewById([Link].bt1);
b2 = findViewById([Link].bt2);
b3 = findViewById([Link].bt3);
Intent i = getIntent();
String t1 = [Link]("id").toString();
String t2 = [Link]("name").toString();
String t3 = [Link]("course").toString();
String t4 = [Link]("fee").toString();
[Link](t1);
[Link](t2);
[Link](t3);
[Link](t4);
[Link](new [Link]() {
@Override
public void onClick(View v) {
Delete();
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),[Link]);
startActivity(i);
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
Edit();
}
});
public void Delete()
{
try
{
String id = [Link]().toString();
SQLiteDatabase db =
openOrCreateDatabase("SliteDb",Context.MODE_PRIVATE,null);
String sql = "delete from records where id = ?";
SQLiteStatement statement = [Link](sql);
[Link](1,id);
[Link]();
[Link](this,"Record Deleted",Toast.LENGTH_LONG).show();
[Link]("");
[Link]("");
[Link]("");
[Link]();
}
catch (Exception ex)
{
[Link](this,"Record Fail",Toast.LENGTH_LONG).show();
}
}
public void Edit()
{
try
{
String name = [Link]().toString();
String course = [Link]().toString();
String fee = [Link]().toString();
String id = [Link]().toString();
SQLiteDatabase db =
openOrCreateDatabase("SliteDb",Context.MODE_PRIVATE,null);
String sql = "update records set name = ?,course=?,fee=? where id= ?";
SQLiteStatement statement = [Link](sql);
[Link](1,name);
[Link](2,course);
[Link](3,fee);
[Link](4,id);
[Link]();
[Link](this,"Record Updateddd",Toast.LENGTH_LONG).show();
[Link]("");
[Link]("");
[Link]("");
[Link]();
}
catch (Exception ex)
{
[Link](this,"Record Fail",Toast.LENGTH_LONG).show();
}