Ejemplo n.º 1
0
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    lesson = (Lesson) this.getIntent().getSerializableExtra("data");

    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle(lesson.getName());

    setContentView(R.layout.activity_lesson_six);
    ButterKnife.bind(this);
    noteDao = new Note_imp();

    btnAdd.setOnClickListener(
        view -> {
          addNote();
        });

    btnSerach.setOnClickListener(
        view -> {
          search(editText.getText().toString());
        });

    // 生成适配器
    sixAdapter = new SixAdapter(this, noteDao.getAllNotes());
    listView.setAdapter(sixAdapter);
    search(null);
  }
Ejemplo n.º 2
0
  private void addNote() {
    // 如果新增为空,弹出
    if (TextUtils.isEmpty(editText.getText())) {
      Toast.makeText(this, "add不能为空", Toast.LENGTH_SHORT);
      return;
    }

    String noteText = editText.getText().toString();
    final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    String comment = "Added on " + df.format(new Date());
    // 插入操作,简单到只要你创建一个 Java 对象
    Note note = new Note(null, noteText, comment, new Date());
    progressDialog = ProgressDialog.show(this, "添加中", "努力添加中,请稍等", true, false);
    noteDao.add(
        note,
        new DaoResponse<List<Note>>() {
          @Override
          public void onSuccess(List<Note> notes) {
            onUpdateList(notes);
            progressDialog.dismiss();
          }

          @Override
          public void onFial(String msg) {}
        });
  }
Ejemplo n.º 3
0
  private void search(String title) {
    progressDialog = ProgressDialog.show(this, "查询中", "努力查询中,请稍等", true, false);
    noteDao.search(
        title,
        new DaoResponse<List<Note>>() {
          @Override
          public void onSuccess(List<Note> notes) {
            progressDialog.dismiss();
            onUpdateList(notes);
          }

          @Override
          public void onFial(String msg) {}
        });
  }