团队冲刺04

  今天改了昨天的代码,用mode来区分添加和修改

  遇到的问题:我混乱了,不仅不能修改,连添加都不能了

  明天解决

@Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {

        int returnMode;  //-1不改变 0创建一个新笔记 1修改当前笔记
        long note_id;
        returnMode = data.getExtras().getInt("mode",-1);
        note_id = data.getExtras().getLong("id",0);
        //修改笔记
        if(returnMode == 1){
            String content = data.getStringExtra("content");
            String time = data.getStringExtra("time");
            int tag = data.getExtras().getInt("tag",1);
            Note newNote = new Note(content,time,tag);
            newNote.setId(note_id);
            dao op = new dao(context);
            op.open();
            op.updateNote(newNote);
            op.close();
            //refreshListView();
        }
        //新建笔记
        else if (returnMode == 0) {
            String content = data.getExtras().getString("content");
            String time = data.getExtras().getString("time");
            int tag = data.getExtras().getInt("tag", 1);

            Note newNote = new Note(content, time, tag);
            dao op = new dao(context);
            op.open();
            op.addNote(newNote);
            op.close();
        }
        //删除笔记
        else if (returnMode == 2){
            Note delNote = new Note();
            delNote.setId(note_id);
            dao op = new dao(context);
            op.open();
            op.removeNote(delNote);
            op.close();
        }
        refreshListView();
        super.onActivityResult(requestCode, resultCode, data);
    }

 

posted on 2020-04-20 21:09  小橘猫xjm  阅读(86)  评论(0编辑  收藏  举报

导航