-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
72 lines (64 loc) · 2.6 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.example.test.testdb;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
TextView tv1, tv2, tv3;
EditText ed1, ed2, ed3;
Button bt1, bt2;
Database db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.t1);
tv2 = (TextView) findViewById(R.id.t2);
tv3 = (TextView) findViewById(R.id.t3);
ed1 = (EditText) findViewById(R.id.edt1);
ed2 = (EditText) findViewById(R.id.edt2);
ed3 = (EditText) findViewById(R.id.edt3);
bt1 = (Button) findViewById(R.id.Btn1);
bt2 = (Button) findViewById(R.id.Btn2);
db = new Database(getApplicationContext());
if (getIntent().getExtras() != null) {
ed1.setText(getIntent().getStringExtra("id"));
ed2.setText(getIntent().getStringExtra("fname"));
ed3.setText(getIntent().getStringExtra("lname"));
bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Student s1 = new Student();
s1.setId(Integer.parseInt(ed1.getText().toString()));
s1.setFname(ed2.getText().toString());
s1.setLname(ed3.getText().toString());
db.update(s1);
Toast.makeText(getApplicationContext(), "updated....", Toast.LENGTH_LONG).show();
}
});
} else {
bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Student s1 = new Student();
s1.setId(Integer.parseInt(ed1.getText().toString()));
s1.setFname(ed2.getText().toString());
s1.setLname(ed3.getText().toString());
db.insert(s1);
Toast.makeText(getApplication(), "Inserted...", Toast.LENGTH_LONG).show();
}
});
}
bt2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplication(), Display.class);
startActivity(i);
}
});
}
}