-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewWord.java
More file actions
71 lines (53 loc) · 2.23 KB
/
NewWord.java
File metadata and controls
71 lines (53 loc) · 2.23 KB
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.murach.russvocab;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
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;
public class NewWord extends Activity {
private EditText edt_1;
private EditText edt_2;
private Button btn_1;
private RussVocabDB russVocabDB;
private SQLiteDatabase RVdb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_word);
edt_1 = (EditText)findViewById(R.id.edt_newWordR);
edt_2 = (EditText)findViewById(R.id.edt_newWordE);
btn_1 = (Button)findViewById(R.id.btn_newWord);
russVocabDB = new RussVocabDB(NewWord.this, "RV.db", null, 1);
RVdb = russVocabDB.getWritableDatabase();
btn_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(Exists(edt_1.getText().toString())){
Toast.makeText(NewWord.this, "Word already exists!", Toast.LENGTH_LONG).show();
}else{
ContentValues cv = new ContentValues();
cv.put("Noun", edt_1.getText().toString() );
cv.put("English", edt_2.getText().toString());
long id = RVdb.insert("NOUNS", null, cv);
Toast.makeText(NewWord.this, String.valueOf(id), Toast.LENGTH_LONG).show();
}
}
});
}
public boolean Exists(String searchItem) {
String[] columns = { "Noun" };
String selection = "Noun" + " =?";
String[] selectionArgs = { searchItem };
String limit = "1";
Cursor cursor = RVdb.query("NOUNS", columns, selection, selectionArgs, null, null, null, limit);
boolean exists = (cursor.getCount() > 0);
cursor.close();
return exists;
}
}