· 8 years ago · Apr 15, 2018, 07:12 PM
1package com.kd.my_national_address.mynationaladdress;
2
3import android.app.Activity;
4import android.content.Context;
5import android.content.SharedPreferences;
6import android.content.pm.ActivityInfo;
7import android.media.AudioManager;
8import android.media.MediaPlayer;
9import android.os.Bundle;
10import android.view.View;
11import android.widget.Button;
12import android.widget.EditText;
13import android.widget.TextView;
14
15
16import android.database.Cursor;
17import android.database.sqlite.SQLiteDatabase;
18
19public class MyaddinfoActivity extends Activity{
20
21 Button close,Add;
22 TextView textView,textView2,t1,t2,t3,t4;
23 EditText editText1,editText2,editText3,editText4;
24
25 int Sc = 0;
26 int Lc = 0;
27
28 int cn = 0;
29
30 String edstring1;
31 String edstring2;
32 String edstring3;
33 String edstring4;
34
35 SQLiteDatabase db;
36
37 @Override
38 protected void onCreate(Bundle savedInstanceState) {
39 super.onCreate(savedInstanceState);
40 setContentView(R.layout.myaddinfo);
41
42 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
43 setVolumeControlStream(AudioManager.STREAM_MUSIC);
44 final MediaPlayer sound1 = MediaPlayer.create(this, R.raw.s1); // sounds 1
45
46
47 textView = (TextView) findViewById(R.id.textView);
48 textView2 = (TextView) findViewById(R.id.textView2);
49
50 t1 = (TextView) findViewById(R.id.t1);
51 t2 = (TextView) findViewById(R.id.t2);
52 t3 = (TextView) findViewById(R.id.t3);
53 t4 = (TextView) findViewById(R.id.t4);
54
55 Add = (Button) findViewById(R.id.button);
56 close = (Button) findViewById(R.id.close);
57
58 editText1 = (EditText) findViewById(R.id.editText1);
59 editText2 = (EditText) findViewById(R.id.editText2);
60 editText3 = (EditText) findViewById(R.id.editText3);
61 editText4 = (EditText) findViewById(R.id.editText4);
62
63 editText1.setEnabled(false);
64 editText2.setEnabled(false);
65 editText3.setEnabled(false);
66 editText4.setEnabled(false);
67
68 // create database Mydatabase
69 db = openOrCreateDatabase("Mydatabase", Context.MODE_PRIVATE, null);
70 // create table Myaddinfo withe the 4
71 db.execSQL("CREATE TABLE IF NOT EXISTS Myaddinfo (address VARCHAR, buildingno INTEGER, postcode INTEGER , additionalno INTEGER);" );
72
73
74 edstring1 = editText1.getText().toString();
75 edstring2 = editText2.getText().toString();
76 edstring3 = editText3.getText().toString();
77 edstring4 = editText4.getText().toString();
78
79 // insert if it emtu nothing
80 if ( edstring1.contentEquals("") && edstring2.contentEquals("") && edstring3.contentEquals("") && edstring4.contentEquals("")) {
81 db.execSQL("INSERT INTO Myaddinfo (address,buildingno,postcode,additionalno) VALUES ('" + "" + "','" + "" + "','" + "" + "','" + "" + "');");
82 }
83
84 // show the data
85 Cursor c = db.rawQuery("SELECT * FROM Myaffinfo", null);
86 c.moveToNext();
87 editText1.setText(c.getString(0));
88 editText2.setText(c.getString(1));
89 editText3.setText(c.getString(2));
90 editText4.setText(c.getString(3));
91
92 //Cursor c2 = db.rawQuery("SELECT address FROM Myaffinfo", null);
93
94
95
96 close.setOnClickListener(new View.OnClickListener() {
97 @Override
98 public void onClick(View v) {
99 if (Sc==0){ sound1.start();}
100 finish();
101 }
102 });
103
104 Add.setOnClickListener(new View.OnClickListener() {
105 @Override
106 public void onClick(View v) {
107 if (Sc==0){ sound1.start();}
108
109
110 if (cn == 0){
111
112 if (Lc==0){Add.setText("ØÙظ");}
113 else {Add.setText("Save");}
114
115 editText1.setEnabled(true);
116 editText2.setEnabled(true);
117 editText3.setEnabled(true);
118 editText4.setEnabled(true);
119
120 cn ++;
121 }
122 else {
123 edstring1 = editText1.getText().toString();
124 edstring2 = editText2.getText().toString();
125 edstring3 = editText3.getText().toString();
126 edstring4 = editText4.getText().toString();
127
128
129 db.execSQL( "INSERT INTO Myaffinfo(address,buildingno,postcode,additionalno) VALUES('" + edstring1 + "','" + edstring2 + "','" + edstring3 + "','" + edstring4 + "');");
130
131
132
133 editText1.setEnabled(false);
134 editText2.setEnabled(false);
135 editText3.setEnabled(false);
136 editText4.setEnabled(false);
137 cn= 0;
138
139
140 }
141
142 }
143 });
144
145
146
147
148
149 }
150}