• 大小: 8KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: Java
  • 标签: 日记本  

资源简介

android日记本!!!!!!!!!!!!!!!!!!!!!!!!!

资源截图

代码片段和文件信息

package com.example.hhsm.myapplication1;

/**
 * Created by hhsm on 2018/6/22.
 */

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Date;
import java.text.SimpleDateFormat;

public class Addcontent extends Activity implements View.onclickListener {


    private Button savebtn deletebtn;
    private EditText ettext;
    private NotesDB notesDB;
    private SQLiteDatabase dbWriter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_list);
        savebtn = (Button) findViewById(R.id.add_save);
        deletebtn = (Button) findViewById(R.id.add_delete);
        ettext = (EditText) findViewById(R.id.add_etv);
        savebtn.setonclickListener(this);
        deletebtn.setonclickListener(this);
        notesDB = new NotesDB(this);
        dbWriter = notesDB.getWritableDatabase();
        ettext.setonfocusChangeListener(new View.onfocusChangeListener() {
            @Override
            public void onfocusChange(View v boolean hasFocus) {
                if (ettext.getText().equals(““)) {
                    new AlertDialog.Builder(Addcontent.this)
                            .settitle(“警告“)
                            .setMessage(“请输入标题“)
                            .setPositiveButton(“确定“ new DialogInterface.onclickListener() {
                                @Override
                                public void onclick(DialogInterface dialog int which) {
                                    dialog.dismiss();
                                    Addcontent.this.finish();
                                }
                            });
                }

            }


            public void onclick(View v) {
                switch (v.getId()) {
                    case R.id.add_save:
                        addDB();
                        finish();
                        break;
                    case R.id.add_delete:
                        finish();
                        break;
                }
            }

            private void addDB() {
                ContentValues cv = new ContentValues();
                cv.put(NotesDB.CONTENT ettext.getText().toString());
                cv.put(NotesDB.TIME getTime());
                dbWriter.insert(NotesDB.TABLE_NAME null cv);
            }

            public String getTime() {
                SimpleDateFormat format = new SimpleDateFormat(“yyy年MM月dd日 HH:mm:ss“);
                Date curDate = new Date();
                String str = format.format(curDate);
                return s

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-07-05 07:09  日记本源码\
     文件        3126  2018-07-04 13:43  日记本源码\Addcontent.java
     文件        1531  2018-07-04 11:12  日记本源码\AndroidManifest.xml
     文件        2234  2018-07-04 11:12  日记本源码\MainActivity.java
     文件        1595  2018-06-22 01:42  日记本源码\MyAdapter.java
     文件        2114  2018-06-08 00:05  日记本源码\MyService.java
     文件         918  2018-06-22 01:43  日记本源码\NotesDB.java
     文件        2631  2018-07-04 11:29  日记本源码\Select.java
     文件         749  2018-06-22 11:00  日记本源码\activity_main.xml
     文件        2153  2018-06-22 11:02  日记本源码\add_list.xml
     文件         815  2018-06-22 01:48  日记本源码\list.xml
     文件        1071  2018-06-22 01:47  日记本源码\select.xml

评论

共有 条评论