├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── add.png │ │ │ │ ├── delete.png │ │ │ │ └── add_notepad.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── public_fanhui.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ ├── public_top.xml │ │ │ │ ├── function_layout.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── notepad_item_layout.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── zhangqie │ │ │ └── notepad │ │ │ ├── ui │ │ │ ├── widget │ │ │ │ └── LinearLayoutForListView.java │ │ │ └── activity │ │ │ │ └── FunctionActivity.java │ │ │ ├── entity │ │ │ └── UserInfo.java │ │ │ ├── base │ │ │ ├── BaseActivity.java │ │ │ └── NotePadOnItemClickListener.java │ │ │ ├── util │ │ │ ├── UtilDB.java │ │ │ └── HelperSQLite.java │ │ │ ├── MainActivity.java │ │ │ └── adapter │ │ │ └── NotePadAdapter.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── zhangqie │ │ │ └── notepad │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── zhangqie │ │ └── notepad │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── .idea ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── modules.xml ├── runConfigurations.xml ├── compiler.xml ├── gradle.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 歆语便签 3 | 4 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DickyQie/android-sqlite/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DickyQie/android-sqlite/HEAD/app/src/main/res/mipmap-xxhdpi/add.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DickyQie/android-sqlite/HEAD/app/src/main/res/mipmap-xxhdpi/delete.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/public_fanhui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DickyQie/android-sqlite/HEAD/app/src/main/res/mipmap-xhdpi/public_fanhui.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/add_notepad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DickyQie/android-sqlite/HEAD/app/src/main/res/mipmap-xxhdpi/add_notepad.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DickyQie/android-sqlite/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #F48FB1 4 | #DC81A0 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/test/java/com/zhangqie/notepad/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.zhangqie.notepad; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Android我的便签-----SQLite的使用方法 2 |

在Android开发中也有数据库的存在,最近有空,把以前写的一个便签来讲述一下Android中的数据库,跟大家分享分享的,希望对大家有所帮助。

3 | 4 |

SQLite简介

5 |

SQLite,是一款轻量级的关系型数据库。由于它占用的资源非常少,所以在很多嵌入式设备都是用SQLite来存储数据。

6 |

 

7 |

SQLite数据库操作和常用的数据库操作差不多;如:MySQL......; 增删改查等语句操作基本相同; 今天给大家Android SQLite语句相关操作的两种方式

8 |

 

9 |

首先来看一下我的便签的效果图:(图中操作顺序:查询,添加,修改,删除)

10 |

        

11 | 12 | 13 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Android\SDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/zhangqie/notepad/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.zhangqie.notepad; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.zhangqie.notepad", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhangqie/notepad/ui/widget/LinearLayoutForListView.java: -------------------------------------------------------------------------------- 1 | package com.zhangqie.notepad.ui.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.ListView; 6 | 7 | public class LinearLayoutForListView extends ListView { 8 | 9 | public LinearLayoutForListView(Context context) { 10 | super(context); 11 | } 12 | public LinearLayoutForListView(Context context, AttributeSet attrs) { 13 | super(context, attrs); 14 | } 15 | public LinearLayoutForListView(Context context, AttributeSet attrs, 16 | int defStyle) { 17 | super(context, attrs, defStyle); 18 | } 19 | @Override 20 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 21 | int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, 22 | MeasureSpec.AT_MOST); 23 | super.onMeasure(widthMeasureSpec, expandSpec); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | defaultConfig { 7 | applicationId "com.zhangqie.notepad" 8 | minSdkVersion 19 9 | targetSdkVersion 22 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:22.2.+' 28 | compile 'com.jakewharton:butterknife:7.0.1' 29 | testCompile 'junit:junit:4.12' 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhangqie/notepad/entity/UserInfo.java: -------------------------------------------------------------------------------- 1 | package com.zhangqie.notepad.entity; 2 | 3 | /** 4 | * Created by zhangqie on 2015/6/26. 5 | */ 6 | 7 | public class UserInfo { 8 | 9 | private String id; 10 | private String userContent; 11 | private String userYear; 12 | private String userTime; 13 | 14 | public String getId() { 15 | return id; 16 | } 17 | 18 | public void setId(String id) { 19 | this.id = id; 20 | } 21 | 22 | public String getUserContent() { 23 | return userContent; 24 | } 25 | 26 | public void setUserContent(String userContent) { 27 | this.userContent = userContent; 28 | } 29 | 30 | public String getUserYear() { 31 | return userYear; 32 | } 33 | 34 | public void setUserYear(String userYear) { 35 | this.userYear = userYear; 36 | } 37 | 38 | public String getUserTime() { 39 | return userTime; 40 | } 41 | 42 | public void setUserTime(String userTime) { 43 | this.userTime = userTime; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhangqie/notepad/base/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.zhangqie.notepad.base; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.text.TextUtils; 7 | import android.widget.Toast; 8 | 9 | import butterknife.ButterKnife; 10 | 11 | /** 12 | * Created by zhangqie on 2015/6/26. 13 | */ 14 | 15 | public abstract class BaseActivity extends AppCompatActivity { 16 | 17 | 18 | @Override 19 | protected void onCreate(@Nullable Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(setContentViewLayout()); 22 | ButterKnife.bind(this); 23 | initBeforeData(); 24 | } 25 | 26 | protected abstract int setContentViewLayout(); 27 | 28 | protected abstract void initBeforeData(); 29 | 30 | protected void showToastShort(String msg){ 31 | if (!TextUtils.isEmpty(msg)) { 32 | Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); 33 | } 34 | } 35 | 36 | @Override 37 | protected void onDestroy() { 38 | super.onDestroy(); 39 | ButterKnife.unbind(this); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhangqie/notepad/base/NotePadOnItemClickListener.java: -------------------------------------------------------------------------------- 1 | package com.zhangqie.notepad.base; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.view.View; 6 | import android.widget.AdapterView; 7 | 8 | import com.zhangqie.notepad.MainActivity; 9 | import com.zhangqie.notepad.entity.UserInfo; 10 | import com.zhangqie.notepad.ui.activity.FunctionActivity; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Created by zhangqie on 2015/6/26. 16 | */ 17 | 18 | public class NotePadOnItemClickListener implements AdapterView.OnItemClickListener { 19 | 20 | private List list; 21 | private MainActivity mainActivity; 22 | public NotePadOnItemClickListener(MainActivity mainActivity,List list) { 23 | this.mainActivity=mainActivity; 24 | this.list=list; 25 | } 26 | @Override 27 | public void onItemClick(AdapterView parent, View view, int position, long id) { 28 | UserInfo userInfo=list.get(position); 29 | Intent intent=new Intent(mainActivity, FunctionActivity.class); 30 | intent.putExtra("id",userInfo.getId()); 31 | intent.putExtra("year",userInfo.getUserYear()); 32 | intent.putExtra("content",userInfo.getUserContent()); 33 | intent.putExtra("time",userInfo.getUserTime()); 34 | mainActivity.startActivityForResult(intent,1); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhangqie/notepad/util/UtilDB.java: -------------------------------------------------------------------------------- 1 | package com.zhangqie.notepad.util; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | /** 7 | * Created by zhangqie on 2015/6/26. 8 | */ 9 | 10 | public class UtilDB { 11 | 12 | public static final String DATABASE_NAME="User";//库名 13 | 14 | public static final String DATABASE_TABLE="UserInfo";//表单名 15 | 16 | public static final int DATABASE_VERION=1;//版本 17 | 18 | //字段 19 | public static final String USER_ID="id"; 20 | 21 | public static final String USER_CONTENT="content"; 22 | 23 | public static final String USER_YEAR="useryear"; 24 | 25 | public static final String USER_TIME="usertime"; 26 | 27 | public static final String showCreateSql(){ 28 | return "create table "+DATABASE_TABLE+"("+USER_ID+" integer primary key autoincrement," 29 | +USER_CONTENT+ " text," + USER_YEAR+ " text,"+USER_TIME+" text)"; 30 | } 31 | 32 | /*** 33 | * 获取当前日历 34 | * @return 35 | */ 36 | public static final String shoTimeYear(){ 37 | SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy年MM月dd日"); 38 | return simpleDateFormat.format(new Date()); 39 | } 40 | 41 | 42 | /*** 43 | * 获取当前时间 44 | * @return 45 | */ 46 | public static final String shoTime(){ 47 | SimpleDateFormat simpleDateFormat=new SimpleDateFormat("ahh:mm"); 48 | return simpleDateFormat.format(new Date()); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/res/layout/public_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 14 | 15 | 27 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/function_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 18 | 23 | 32 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 16 | 27 | 28 | 29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/notepad_item_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | 24 | 25 | 36 | 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhangqie/notepad/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.zhangqie.notepad; 2 | 3 | 4 | import android.content.Intent; 5 | 6 | import com.zhangqie.notepad.base.BaseActivity; 7 | import com.zhangqie.notepad.adapter.NotePadAdapter; 8 | import com.zhangqie.notepad.base.NotePadOnItemClickListener; 9 | import com.zhangqie.notepad.entity.UserInfo; 10 | import com.zhangqie.notepad.ui.activity.FunctionActivity; 11 | import com.zhangqie.notepad.ui.widget.LinearLayoutForListView; 12 | import com.zhangqie.notepad.util.HelperSQLite; 13 | 14 | import java.util.List; 15 | 16 | import butterknife.Bind; 17 | import butterknife.OnClick; 18 | 19 | public class MainActivity extends BaseActivity { 20 | 21 | @Bind(R.id.listview) 22 | LinearLayoutForListView listview; 23 | 24 | HelperSQLite helperSQLite; 25 | List list; 26 | 27 | @Override 28 | protected int setContentViewLayout() { 29 | return R.layout.activity_main; 30 | } 31 | 32 | @Override 33 | protected void initBeforeData() { 34 | helperSQLite=new HelperSQLite(this); 35 | showQueryData(); 36 | } 37 | 38 | private void showQueryData(){ 39 | if (list!=null){ 40 | list.clear(); 41 | } 42 | list=helperSQLite.query(); 43 | listview.setAdapter(new NotePadAdapter(this,list)); 44 | listview.setOnItemClickListener(new NotePadOnItemClickListener(this,list)); 45 | } 46 | 47 | 48 | @OnClick(R.id.add) 49 | public void onClick() { 50 | startActivityForResult(new Intent(this,FunctionActivity.class),1); 51 | } 52 | 53 | @Override 54 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 55 | super.onActivityResult(requestCode, resultCode, data); 56 | if (requestCode==1){ 57 | if (resultCode==2){ 58 | showQueryData(); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhangqie/notepad/adapter/NotePadAdapter.java: -------------------------------------------------------------------------------- 1 | package com.zhangqie.notepad.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.TextView; 9 | 10 | import com.zhangqie.notepad.R; 11 | import com.zhangqie.notepad.entity.UserInfo; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Created by zhnagqie on 2015/6/26. 17 | */ 18 | 19 | public class NotePadAdapter extends BaseAdapter { 20 | 21 | private LayoutInflater layoutInflater; 22 | 23 | private List list; 24 | 25 | public NotePadAdapter(Context context,List list){ 26 | this.layoutInflater=LayoutInflater.from(context); 27 | this.list=list; 28 | } 29 | 30 | @Override 31 | public int getCount() { 32 | return list==null ? 0 : list.size(); 33 | } 34 | 35 | @Override 36 | public Object getItem(int position) { 37 | return list.get(position); 38 | } 39 | 40 | @Override 41 | public long getItemId(int position) { 42 | return position; 43 | } 44 | 45 | @Override 46 | public View getView(int position, View convertView, ViewGroup parent) { 47 | ViewHolder viewHolder; 48 | if (convertView==null){ 49 | convertView=layoutInflater.inflate(R.layout.notepad_item_layout,null); 50 | viewHolder=new ViewHolder(convertView); 51 | convertView.setTag(viewHolder); 52 | }else { 53 | viewHolder=(ViewHolder) convertView.getTag(); 54 | } 55 | UserInfo userInfo=(UserInfo) getItem(position); 56 | viewHolder.tvNotepadYear.setText(userInfo.getUserYear()); 57 | viewHolder.tvNoteoadContent.setText(userInfo.getUserContent()); 58 | viewHolder.tvNoteoadTime.setText(userInfo.getUserTime()); 59 | return convertView; 60 | } 61 | 62 | class ViewHolder{ 63 | TextView tvNotepadYear; 64 | TextView tvNoteoadContent; 65 | TextView tvNoteoadTime; 66 | public ViewHolder(View view){ 67 | tvNotepadYear=(TextView) view.findViewById(R.id.notepad_item_year); 68 | tvNoteoadContent=(TextView) view.findViewById(R.id.notepad_item_content); 69 | tvNoteoadTime=(TextView) view.findViewById(R.id.notepad_item_time); 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhangqie/notepad/ui/activity/FunctionActivity.java: -------------------------------------------------------------------------------- 1 | package com.zhangqie.notepad.ui.activity; 2 | 3 | import android.content.Intent; 4 | import android.view.View; 5 | import android.widget.EditText; 6 | import android.widget.ImageView; 7 | import android.widget.TextView; 8 | 9 | import com.zhangqie.notepad.R; 10 | import com.zhangqie.notepad.base.BaseActivity; 11 | import com.zhangqie.notepad.util.HelperSQLite; 12 | import com.zhangqie.notepad.util.UtilDB; 13 | 14 | import butterknife.Bind; 15 | import butterknife.OnClick; 16 | 17 | /** 18 | * Created by zhangqie on 2015/6/26. 19 | */ 20 | 21 | public class FunctionActivity extends BaseActivity { 22 | 23 | @Bind(R.id.notepad_close) 24 | ImageView notepadClose; 25 | @Bind(R.id.notepad_name) 26 | TextView notepadName; 27 | @Bind(R.id.notepad_content) 28 | EditText notepadContent; 29 | 30 | String id; 31 | HelperSQLite helperSQLite; 32 | 33 | @Override 34 | protected int setContentViewLayout() { 35 | return R.layout.function_layout; 36 | } 37 | 38 | @Override 39 | protected void initBeforeData() { 40 | notepadClose.setVisibility(View.VISIBLE); 41 | Intent intent=getIntent(); 42 | if(intent!= null){ 43 | id=intent.getStringExtra("id"); 44 | if (id!=null){ 45 | notepadName.setText(intent.getStringExtra("year")+intent.getStringExtra("time")); 46 | notepadContent.setText(intent.getStringExtra("content")); 47 | }else { 48 | notepadName.setText("添加语录"); 49 | } 50 | }else { 51 | notepadName.setText("添加语录"); 52 | } 53 | helperSQLite=new HelperSQLite(this); 54 | } 55 | 56 | 57 | @OnClick({R.id.notepad_close, R.id.delete, R.id.note_add}) 58 | public void onClick(View view) { 59 | switch (view.getId()) { 60 | case R.id.notepad_close: 61 | finish(); 62 | break; 63 | case R.id.delete: 64 | if (id!=null){ 65 | if (helperSQLite.deleteData(id)){ 66 | showToastShort("删除成功!"); 67 | setResult(2); 68 | finish(); 69 | }else { 70 | showToastShort("删除失败!"); 71 | } 72 | }else { 73 | notepadContent.setText(""); 74 | } 75 | break; 76 | case R.id.note_add: 77 | String noteContent=notepadContent.getText().toString().trim(); 78 | if (id!=null){//修改操作 79 | if (noteContent.length()>0){ 80 | if (helperSQLite.updateData(id,noteContent, UtilDB.shoTimeYear(),UtilDB.shoTime())){ 81 | showToastShort("修改成功!"); 82 | setResult(2); 83 | finish(); 84 | }else { 85 | showToastShort("修改失败!"); 86 | } 87 | }else { 88 | showToastShort("修改内容不能为空!"); 89 | } 90 | }else {//添加 91 | if (noteContent.length()>0){ 92 | 93 | if (helperSQLite.insertDate(noteContent, UtilDB.shoTimeYear(),UtilDB.shoTime())){ 94 | showToastShort("添加成功!"); 95 | setResult(2); 96 | finish(); 97 | }else { 98 | showToastShort("添加失败!"); 99 | } 100 | }else { 101 | showToastShort("添加内容不能为空!"); 102 | } 103 | } 104 | break; 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhangqie/notepad/util/HelperSQLite.java: -------------------------------------------------------------------------------- 1 | package com.zhangqie.notepad.util; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | import android.database.sqlite.SQLiteOpenHelper; 8 | 9 | import com.zhangqie.notepad.entity.UserInfo; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * Created by zhangqie on 2015/6/26.. 16 | */ 17 | 18 | public class HelperSQLite extends SQLiteOpenHelper{ 19 | 20 | private SQLiteDatabase sqLiteDatabase; 21 | 22 | /*** 23 | * 创建数据库 24 | * @param context 25 | */ 26 | public HelperSQLite(Context context){ 27 | super(context, UtilDB.DATABASE_NAME, null, UtilDB.DATABASE_VERION); 28 | sqLiteDatabase=this.getWritableDatabase(); 29 | } 30 | 31 | /*** 32 | * 创建表 33 | * @param db 34 | */ 35 | @Override 36 | public void onCreate(SQLiteDatabase db) { 37 | db.execSQL(UtilDB.showCreateSql()); 38 | } 39 | 40 | @Override 41 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 42 | 43 | } 44 | 45 | /*** 46 | * 添加数据 47 | * @param userContent 48 | * @param userYear 49 | * @param userTime 50 | * @return 51 | */ 52 | public boolean insertDate(String userContent,String userYear,String userTime){ 53 | 54 | //方式1 SQL语句的方式 55 | /* String stu_sql="insert into "+UtilDB.DATABASE_TABLE+"("+UtilDB.USER_CONTENT+","+UtilDB.USER_YEAR+","+UtilDB.USER_TIME+") values('"+userContent+"','"+userYear+"','"+userTime+"')"; 56 | sqLiteDatabase.execSQL(stu_sql); 57 | return true;*/ 58 | //方式2 59 | ContentValues contentValues=new ContentValues(); 60 | contentValues.put(UtilDB.USER_CONTENT,userContent); 61 | contentValues.put(UtilDB.USER_YEAR,userYear); 62 | contentValues.put(UtilDB.USER_TIME,userTime); 63 | return sqLiteDatabase.insert(UtilDB.DATABASE_TABLE,null,contentValues)>0; 64 | 65 | } 66 | 67 | /*** 68 | * 删除数据 69 | * @param id 70 | * @return 71 | */ 72 | public boolean deleteData(String id){ 73 | 74 | 75 | /*String sql = "delete from "+UtilDB.DATABASE_TABLE+" where "+UtilDB.USER_ID+" = "+id; 76 | sqLiteDatabase.execSQL(sql); 77 | return true;*/ 78 | 79 | String sql=UtilDB.USER_ID+"=?"; 80 | String[] contentValuesArray=new String[]{String.valueOf(id)}; 81 | return sqLiteDatabase.delete(UtilDB.DATABASE_TABLE,sql,contentValuesArray)>0; 82 | } 83 | 84 | /**** 85 | * 修改数据 86 | * @param id 87 | * @param content 88 | * @param userYear 89 | * @param userTime 90 | * @return 91 | */ 92 | public boolean updateData(String id,String content,String userYear,String userTime){ 93 | /* String sql = "update "+UtilDB.DATABASE_TABLE+" set "+UtilDB.USER_CONTENT+" = '"+content+"'," 94 | +UtilDB.USER_YEAR+" = '"+userYear+"',"+UtilDB.USER_TIME+"='"+userTime+"' where "+UtilDB.USER_ID+" = "+id; 95 | sqLiteDatabase.execSQL(sql); 96 | return true;*/ 97 | ContentValues contentValues=new ContentValues(); 98 | contentValues.put(UtilDB.USER_CONTENT,content); 99 | contentValues.put(UtilDB.USER_YEAR,userYear); 100 | contentValues.put(UtilDB.USER_TIME,userTime); 101 | String sql=UtilDB.USER_ID+"=?"; 102 | String[] strings=new String[]{id}; 103 | return sqLiteDatabase.update(UtilDB.DATABASE_TABLE,contentValues,sql,strings)>0; 104 | } 105 | 106 | /*** 107 | * 查询数据 108 | * @return 109 | */ 110 | public List query(){ 111 | List list=new ArrayList(); 112 | Cursor cursor=sqLiteDatabase.query(UtilDB.DATABASE_TABLE,null,null,null,null,null,UtilDB.USER_ID+" desc"); 113 | if (cursor!=null){ 114 | while (cursor.moveToNext()){ 115 | UserInfo userInfo=new UserInfo(); 116 | userInfo.setId(String.valueOf(cursor.getInt(cursor.getColumnIndex(UtilDB.USER_ID)))); 117 | userInfo.setUserContent(cursor.getString(cursor.getColumnIndex(UtilDB.USER_CONTENT))); 118 | userInfo.setUserYear(cursor.getString(cursor.getColumnIndex(UtilDB.USER_YEAR))); 119 | userInfo.setUserTime(cursor.getString(cursor.getColumnIndex(UtilDB.USER_TIME))); 120 | list.add(userInfo); 121 | } 122 | } 123 | return list; 124 | } 125 | 126 | 127 | 128 | 129 | } 130 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | --------------------------------------------------------------------------------