コード例 #1
0
ファイル: DAL_Word.java プロジェクト: UProj/BurmaLearnBurmese
  @Override
  public List<Word> getWords() {
    List<Word> wordList = new ArrayList<Word>();
    Db_Help dbhelper = new Db_Help(mContext);
    String query = "SELECT _id,vocab,pronunciation,meaning FROM tb_words;";
    ArrayList datatable = new ArrayList();
    try {
      datatable = dbhelper.getDataTable(query);

      int i = 0;
      while (datatable.size() > i) {
        HashMap tablerow = new HashMap();
        tablerow = (HashMap) datatable.get(i);
        Word obj =
            new Word(
                tablerow.get(tbWord.id).toString(),
                tablerow.get(tbWord.vocab).toString(),
                tablerow.get(tbWord.prounuciation).toString(),
                tablerow.get(tbWord.meaning).toString());

        wordList.add(obj);
        i++;
      }

    } catch (SQLiteException e) {
      Log.e("SQLITE_Exception", e.getMessage());
    }
    return wordList;
  }
コード例 #2
0
ファイル: DAL_Word.java プロジェクト: UProj/BurmaLearnBurmese
  @Override
  public List<Word> getShuffleWords() {
    Random rnd = new Random();
    List<Word> wordList = new ArrayList<Word>();
    Db_Help dbhelper = new Db_Help(mContext);
    String query = "SELECT _id,vocab,pronunciation,meaning FROM tb_words;";
    ArrayList datatable = new ArrayList();
    try {
      datatable = dbhelper.getDataTable(query);

      int i = 0;
      while (datatable.size() > i) {
        HashMap tablerow = new HashMap();
        tablerow = (HashMap) datatable.get(i);
        Word obj =
            new Word(
                tablerow.get(tbWord.id).toString(),
                tablerow.get(tbWord.vocab).toString(),
                tablerow.get(tbWord.prounuciation).toString(),
                tablerow.get(tbWord.meaning).toString());

        wordList.add(obj);
        i++;
      }

    } catch (SQLiteException e) {
      Log.e("SQLITE_Exception", e.getMessage());
    }

    for (int i = wordList.size() - 1; i > 0; i--) {
      int index = rnd.nextInt(i + 1);
      Log.e("Random", String.valueOf(index));
      Word w = wordList.get(index);
      wordList.set(index, wordList.get(i));
      wordList.set(i, w);
    }

    return wordList;
  }