Coder Social home page Coder Social logo

notepad's Introduction

NotePad——android备忘录

一、基本功能实现

1、主界面实现

主界面

(1)当点击下方的添加按钮会进入编辑界面

实现代码:

fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(MainActivity.this,CreateNewNoteActivity.class);
                startActivity(intent);
            }
        });

(2)当点击右上角的放大镜会对所有便签进行搜索

实现代码:

 public void showNotes(String str){
        Cursor cursor=db.rawQuery("select * from notes where title like '%"+str+"%'",null);
        if(cursor.moveToFirst()){
            do {
                int nid=cursor.getInt(0);
                String ntitle=cursor.getString(1);
                String nbody=cursor.getString(2);
                String date=cursor.getString(3);
                Note note=new Note(nid,ntitle,nbody,date);
                noteList.add(note);
            }while (cursor.moveToNext());
        }
    }

2、便签编辑界面

编辑界面

(1)当点击保存时,此数据便会插入数据库当中,并且获取当前时间

实现代码:

public void bindListening(){
        saveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String title=titleEdit.getText().toString();
                String body=bodyEdit.getText().toString();
                SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy.MM.dd HH:m");
                Date date=new Date(System.currentTimeMillis());
                String cdate=simpleDateFormat.format(date);
                db.execSQL("insert into notes(title,body,date) values('"+title+"','"+body+"','"+cdate+"')");
                Toast.makeText(CreateNewNoteActivity.this,"添加成功!",Toast.LENGTH_SHORT).show();
                MainActivity.myHandler.sendEmptyMessage(0x123);
                finish();
            }
        });

(2)当点击删除时,此数据便会从数据库中移出

public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if(id==R.id.ed_delete){
            db=dbHelper.getWritableDatabase();
            db.execSQL("delete from notes where id="+this.id);
            Message message=new Message();
            message.arg1=position;
            message.what=0x125;
            MainActivity.myHandler.sendMessage(message);
            finish();
        }

        return super.onOptionsItemSelected(item);
    }

(3)当重新打开便签,并对内容进行修改保存,则会重新获取时间提示修改成功。

 public void bindListening(){
        saveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                db=dbHelper.getWritableDatabase();
                String title=titleEdit.getText().toString();
                String body=bodyEdit.getText().toString();
                SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy.MM.dd. HH:mm");
                Date date=new Date(System.currentTimeMillis());
                String cdate=simpleDateFormat.format(date);
                db.execSQL("update notes set title=?,body=?,date=? where id="+id,new String[]{title,body,cdate});
                Toast.makeText(EditNoteActivity.this,"修改成功!",Toast.LENGTH_SHORT).show();
                Note note=new Note(id,title,body,cdate);
                Message message=new Message();
                message.what=0x124;
                message.obj=note;
                message.arg1=position;
                MainActivity.myHandler.sendMessage(message);
                finish();
            }
        });

3、便签搜索界面

实现代码:

public void showNotes(String str){
        Cursor cursor=db.rawQuery("select * from notes where title like '%"+str+"%'",null);
        if(cursor.moveToFirst()){
            do {
                int nid=cursor.getInt(0);
                String ntitle=cursor.getString(1);
                String nbody=cursor.getString(2);
                String date=cursor.getString(3);
                Note note=new Note(nid,ntitle,nbody,date);
                noteList.add(note);
            }while (cursor.moveToNext());
        }
    }

二、扩展功能实现

UI美化

notepad's People

Contributors

augustwuli avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.