示例#1
0
  @Override
  public List<Lecture> getLectures(String query) {

    String sql = null;
    Cursor cur = null;
    SQLiteDatabase newlecDB =
        context.openOrCreateDatabase("newlecture", Context.MODE_PRIVATE, null);

    if (query.equals("") || query == null) {
      sql = "SELECT * FROM Lectures";
      cur = newlecDB.rawQuery(sql, null);
    } else {
      sql = "SELECT * FROM Lectures WHERE Title like ?";
      cur = newlecDB.rawQuery(sql, new String[] {"%" + query + "%"});
    }

    List<Lecture> list = new ArrayList<Lecture>();
    while (cur.moveToNext()) {
      Lecture lecture = new Lecture();
      lecture.setCode(cur.getString(0));
      lecture.setTitle(cur.getString(1));
      lecture.setDegree(cur.getString(2));
      lecture.setPrice(cur.getInt(3));
      lecture.setImage(BitmapFactory.decodeResource(context.getResources(), R.drawable.sam));

      list.add(lecture);
    }

    cur.close();
    newlecDB.close();

    return list;
  }
示例#2
0
  @Override
  public Lecture getLecture(String code) {
    String sql = "SELECT * FROM Lectures where code =?";

    SQLiteDatabase newlecDB =
        context.openOrCreateDatabase("newlecture", Context.MODE_PRIVATE, null);
    Cursor cur = newlecDB.rawQuery(sql, new String[] {code});

    Lecture lecture = null;
    if (cur.moveToNext()) {
      lecture = new Lecture();
      lecture.setCode(cur.getString(0));
      lecture.setTitle(cur.getString(1));
      lecture.setDegree(cur.getString(2));
      lecture.setPrice(cur.getInt(3));
      lecture.setImage(BitmapFactory.decodeResource(context.getResources(), R.drawable.sam));
    }

    cur.close();
    newlecDB.close();

    return lecture;
  }