Beispiel #1
0
        public void onClick(View v) {
          db = mHelper.getWritableDatabase();
          if (ePronun.getText().toString().contentEquals("")
              || eMeaning.getText().toString().contentEquals("")) {
            if (eWord.getText().toString().contentEquals(""))
              Toast.makeText(context, "nothing's received", Toast.LENGTH_SHORT).show();
            else {
              db.execSQL("DELETE from Words where name = '" + eWord.getText() + "'");
              Toast.makeText(context, "successfully deleted", Toast.LENGTH_SHORT).show();
            }

          } else {
            db.execSQL(
                "INSERT INTO Words VALUES (null, '"
                    + eWord.getText()
                    + "', 'past', '"
                    + ePronun.getText()
                    + "', '"
                    + eMeaning.getText()
                    + "', 3);");
            Toast.makeText(context, "successfully inserted", Toast.LENGTH_SHORT).show();
          }
          eWord.setText(null);
          ePronun.setText(null);
          eMeaning.setText(null);
          resultRefresh();
        }
Beispiel #2
0
  /** 결과 새로고침 */
  public void resultRefresh() {
    db = mHelper.getReadableDatabase();
    cursor = db.rawQuery("SELECT name, past, pronun, mean, level FROM Words", null);

    // 하나씩 스트링에 넣고 출력
    String Result = "";
    while (cursor.moveToNext()) {
      String name = cursor.getString(0);
      String past = cursor.getString(1);
      String pronun = cursor.getString(2);
      String mean = cursor.getString(3);
      int level = cursor.getInt(4);
      Result += (name + ", " + past + ", " + pronun + ", " + mean + ", " + level + "\n");
    }
    if (Result.length() == 0) {
      mShow.setText("데이터가 없습니다");
    } else {
      mShow.setText(Result);
    }
    cursor.close();
  }