Android记事本

  • a0_259231
    了解作者
  • 1.5MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-05 04:14
    上传日期
Android NoteBook系统,内部有文档说明,PS:适合东软的使用
Android记事本说明文档.rar
内容介绍
package qzk.NoteBook; import java.util.ArrayList; import java.util.List; import qzk.NoteBook.R; import android.app.AlertDialog; import android.app.ListActivity; import android.content.DialogInterface; import android.content.Intent; import android.content.DialogInterface.OnClickListener; import android.content.pm.ActivityInfo; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.Toast; import android.widget.LinearLayout.LayoutParams; public class NoteList extends ListActivity{ private List<NoteInfo> list = new ArrayList<NoteInfo>(); private NoteAdapter adapter; private final int NSort = Menu.FIRST; private final int NSearch = Menu.FIRST+1; private final int NEdit = Menu.FIRST+2; private final int NNew = Menu.FIRST+3; private final int NDelete = Menu.FIRST+4; private final int NAll = Menu.FIRST+5; private final int NColse = Menu.FIRST+6; private final int NDeleteAll = Menu.FIRST+7; private final int NChange = Menu.FIRST+8; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.note_list); list = getDiaryList(NoteSQL.selectNormal(this)); adapter = new NoteAdapter(this, list); setListAdapter(adapter); } @Override protected void onStart() { if(getIntent().hasExtra("mysort")) seeSort(getIntent().getStringExtra("mysort").toString()); if(list.size()>0) setSelection(0); super.onStart(); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Intent i = new Intent(this, NoteShow.class); i.putExtra("dedit", list.get(position).mid); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); } private void seeSort(String sort){ list.clear(); DataBaseHelper helper = new DataBaseHelper(this, DataBaseInfo.DB_NAME, null, 1); SQLiteDatabase db = helper.getReadableDatabase(); Cursor mc = db.rawQuery("select _id, "+ DataBaseInfo.N_TITLE+","+ DataBaseInfo.N_TIME+","+ DataBaseInfo.N_SORT+" from "+ DataBaseInfo.NOTE_TABLE+" where "+DataBaseInfo.N_SORT+" = '"+ sort +"' order by _id desc", null); list.addAll(getDiaryList(mc)); adapter.notifyDataSetChanged(); db.close(); } private void seeAll(){ list.clear(); list.addAll(getDiaryList(NoteSQL.selectAll(this))); adapter.notifyDataSetChanged(); } private List<NoteInfo> getDiaryList(Cursor cursor){ List<NoteInfo> dl = new ArrayList<NoteInfo>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { NoteInfo diaryInfo = new NoteInfo(); diaryInfo.mid = cursor.getInt(0); diaryInfo.mtitle = cursor.getString(1); diaryInfo.mtime = cursor.getString(2); diaryInfo.msort = cursor.getString(3); dl.add(diaryInfo); cursor.moveToNext(); } return dl; } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(0, NNew, Menu.NONE, "新建").setIcon(R.drawable.nnew); menu.add(0, NEdit, Menu.NONE, "修改").setIcon(R.drawable.edit); menu.add(0, NSort, Menu.NONE, "查看分类").setIcon(R.drawable.sort); menu.add(0, NChange, Menu.NONE, "旋转屏幕").setIcon(R.drawable.refresh); menu.add(0, NSearch, Menu.NONE, "查找记事").setIcon(R.drawable.book_search); menu.add(0, NDelete, Menu.NONE, "删除").setIcon(R.drawable.delete); menu.add(0, NAll, Menu.NONE, "查看全部").setIcon(R.drawable.find); menu.add(0, NColse, Menu.NONE, "关闭").setIcon(R.drawable.close); menu.add(0, NDeleteAll, Menu.NONE, "清空记事").setIcon(R.drawable.clear); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case NSort: Intent si = new Intent(this, SortList.class); startActivity(si); return true; case NChange: changeSreen(); return true; case NSearch: addDialog(); return true; case NEdit: if(getSelectedItemPosition()>=0){ Intent edit = new Intent(this, NoteEdit.class); edit.putExtra("dedit", list.get(getSelectedItemPosition()).mid); startActivity(edit); }else Toast.makeText(NoteList.this, "您没有选择要修改的记事!", Toast.LENGTH_LONG).show(); return true; case NNew: Intent i = new Intent(this, NoteEdit.class); startActivity(i); finish(); return true; case NDelete: if(getSelectedItemPosition() >=0) deleteOneDialog(); else Toast.makeText(NoteList.this, "您没有选择要修改的记事!", Toast.LENGTH_LONG).show(); return true; case NAll: seeAll(); return true; case NColse: finish(); return true; case NDeleteAll: deleteAllDialog(); return true; } return false; } private void deleteOneDialog(){ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("温馨提示"); builder.setMessage("你确定要删除这篇记事:"+ list.get(getSelectedItemPosition()).mtitle+"吗?"); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setPositiveButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int id = list.get(getSelectedItemPosition()).mid; NoteSQL.deleteOne(NoteList.this, id); list.remove(getSelectedItemPosition()); adapter.notifyDataSetChanged(); } }); builder.setNegativeButton("取消", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } private void deleteAllDialog(){ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("温馨提示"); builder.setMessage("你确定要删除所有记事吗?"); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setPositiveButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { NoteSQL.deleteAll(NoteList.this); list.clear(); adapter.notifyDataSetChanged(); } }); builder.setNegativeButton("取消", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } private void addDialog(){ AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("关键字搜索"); alert.setIcon(R.drawable.book_search); LinearLayout l = new LinearLayout(this); l.setPadding(5, 4, 5, 4); final EditText input = new EditText(this); input.setHint("请输入关键字"); l.addView(input, new LinearLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); alert.setView(l); alert.setPositiveButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String searchStr = input.getText().toString().trim(); if(searchStr.length()>0){ DataBaseHelper helper = new DataBaseHelper(NoteList.this, DataBaseInfo.DB_NAME, null, 1); SQLiteDatabase db = helper.getReadableDatabase(); Cursor c = db.rawQuery("select _id, "+ DataBaseInfo.N_TITLE+","+DataBaseInfo.N_TIME+","+ DataBaseInfo.N_SORT+" from "+DataBaseInfo.NOTE_TABLE+ " where "+DataBaseInfo.N_
评论
    相关推荐
    • android
      掌握Android Studio开发环境的搭建步骤,能够独立搭建 Android Studio开发环境
    • android
      android
    • android
      Android回购
    • android
      android
    • android课件
      清华老师上课的android课件。ch_01android概述ch_02android开发基础ch_03资源的访问ch_04android用户界面ch_05Ativity和Intent。其他自己看。
    • androidandroid
      androidandroidandroidandroidandroidandroidandroid
    • Android 教程
      Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android 案例 教程,Android ...
    • Android
      Android
    • Android
      Android