Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FisAyarActivity extends Activity {
- private static final String Sentence = "Sentence";
- private Veritabani datas;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.fisayar);
- datas = new Veritabani(this);
- final EditText cumle = (EditText)findViewById(R.id.fisayar_etCumle);
- Button kaydet = (Button)findViewById(R.id.fisayar_btnEkle);
- kaydet.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- try {
- String sentence = cumle.getText().toString();
- CumleEkle(sentence);
- String[] kelimeler = sentence.split(" ");
- int sayi = IdBul(sentence);
- KelimeEkle(sayi, kelimeler);
- cumle.setText("");
- Toast toast = Toast.makeText(getApplicationContext(), sentence+" veritaban�na kaydedildi...", Toast.LENGTH_LONG);
- toast.setGravity(Gravity.CENTER|Gravity.CENTER, 0, 0);
- toast.show();
- } finally {
- datas.close();
- }
- }
- });
- }
- private void CumleEkle(String cumle){
- SQLiteDatabase db = datas.getWritableDatabase();
- ContentValues dataes = new ContentValues();
- dataes.put("Sentence", cumle);
- db.insertOrThrow("Sentences", null, dataes);
- }
- private int IdBul(String cumle){
- SQLiteDatabase db = datas.getReadableDatabase();
- String[] colon = {"SentencesID"};
- Cursor cursor = db.query("Sentences", colon, Sentence + "=?", new String[] { String.valueOf(cumle) }, null, null, null, null);
- int id=0;
- while(cursor.moveToNext()){
- String wordId = cursor.getString((cursor.getColumnIndex("SentencesID")));
- id = Integer.parseInt(wordId);
- }
- return id;
- }
- private void KelimeEkle(int sayi, String[] kelimeler){
- SQLiteDatabase db = datas.getWritableDatabase();
- ContentValues dataes2 = new ContentValues();
- dataes2.put("WordStID", sayi);
- for(int i=0;i<kelimeler.length;i++){
- dataes2.put("Word", kelimeler[i]);
- db.insertOrThrow("Words", null, dataes2);
- }
- }
- }
Add Comment
Please, Sign In to add comment