Guest User

Untitled

a guest
Mar 22nd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. public class FisAyarActivity extends Activity {
  2.  
  3. private static final String Sentence = "Sentence";
  4. private Veritabani datas;
  5.  
  6. @Override
  7. protected void onCreate(Bundle savedInstanceState) {
  8. super.onCreate(savedInstanceState);
  9. setContentView(R.layout.fisayar);
  10.  
  11. datas = new Veritabani(this);
  12.  
  13. final EditText cumle = (EditText)findViewById(R.id.fisayar_etCumle);
  14. Button kaydet = (Button)findViewById(R.id.fisayar_btnEkle);
  15.  
  16. kaydet.setOnClickListener(new View.OnClickListener() {
  17.  
  18. @Override
  19. public void onClick(View v) {
  20. try {
  21.  
  22. String sentence = cumle.getText().toString();
  23. CumleEkle(sentence);
  24. String[] kelimeler = sentence.split(" ");
  25. int sayi = IdBul(sentence);
  26. KelimeEkle(sayi, kelimeler);
  27. cumle.setText("");
  28.  
  29. Toast toast = Toast.makeText(getApplicationContext(), sentence+" veritaban�na kaydedildi...", Toast.LENGTH_LONG);
  30. toast.setGravity(Gravity.CENTER|Gravity.CENTER, 0, 0);
  31. toast.show();
  32. } finally {
  33. datas.close();
  34. }
  35. }
  36. });
  37.  
  38.  
  39. }
  40. private void CumleEkle(String cumle){
  41. SQLiteDatabase db = datas.getWritableDatabase();
  42. ContentValues dataes = new ContentValues();
  43. dataes.put("Sentence", cumle);
  44. db.insertOrThrow("Sentences", null, dataes);
  45. }
  46.  
  47. private int IdBul(String cumle){
  48. SQLiteDatabase db = datas.getReadableDatabase();
  49. String[] colon = {"SentencesID"};
  50. Cursor cursor = db.query("Sentences", colon, Sentence + "=?", new String[] { String.valueOf(cumle) }, null, null, null, null);
  51. int id=0;
  52. while(cursor.moveToNext()){
  53. String wordId = cursor.getString((cursor.getColumnIndex("SentencesID")));
  54. id = Integer.parseInt(wordId);
  55. }
  56. return id;
  57. }
  58. private void KelimeEkle(int sayi, String[] kelimeler){
  59. SQLiteDatabase db = datas.getWritableDatabase();
  60. ContentValues dataes2 = new ContentValues();
  61. dataes2.put("WordStID", sayi);
  62. for(int i=0;i<kelimeler.length;i++){
  63. dataes2.put("Word", kelimeler[i]);
  64. db.insertOrThrow("Words", null, dataes2);
  65. }
  66. }
  67. }
Add Comment
Please, Sign In to add comment