Android记事本NotePad应用功能拓展(1)

本文介绍了Android应用中的事件处理,如回退键事件,以及笔记列表的显示、搜索过滤和删除功能的实现。还包括了数据库操作和未来UI美化的计划,以及分享的学习资源——2021年大厂面试真题和系统学习资料。
摘要由CSDN通过智能技术生成

else if (keyCode == KeyEvent.KEYCODE_BACK){

autoSetMessage();//自动保存

setResult(RESULT_OK, intent);

finish();

return true;

}

return super.onKeyDown(keyCode, event);

}

public void autoSetMessage(){

if(openMode == 4){

if(et.getText().toString().length() == 0){

intent.putExtra(“mode”, -1); //nothing new happens.

}

else{

intent.putExtra(“mode”, 0); // new one note;

intent.putExtra(“content”, et.getText().toString());

intent.putExtra(“time”, dateToStr());//保存时间

intent.putExtra(“tag”, tag);

}

}

else {

if (et.getText().toString().equals(old_content) && !tagChange)

intent.putExtra(“mode”, -1); // edit nothing

else {

intent.putExtra(“mode”, 1); //edit the content

intent.putExtra(“content”, et.getText().toString());

intent.putExtra(“time”, dateToStr());

intent.putExtra(“id”, id);

intent.putExtra(“tag”, tag);

}

}

}

public String dateToStr(){

Date date = new Date();

SimpleDateFormat simpleDateFormat = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);

return simpleDateFormat.format(date);

}

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fvp72egr-1591379236975)(data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==)]

2.添加笔记查询功能(根据标题查询)

@Override

public View getView(int position, View convertView, ViewGroup parent) {

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);

mContext.setTheme(R.style.DayTheme);

View v = View.inflate(mContext, R.layout.note_layout, null);

TextView tv_content = (TextView)v.findViewById(R.id.tv_content);

TextView tv_time = (TextView)v.findViewById(R.id.tv_time);

//Set text for TextView

String allText = noteList.get(position).getContent();

/*if (sharedPreferences.getBoolean(“noteTitle” ,true))

tv_content.setText(allText.split(“\n”)[0]);*/

tv_content.setText(allText);

tv_time.setText(noteList.get(position).getTime());

//Save note id to tag

v.setTag(noteList.get(position).getId());

return v;

}

@Override

public Filter getFilter() {

if (mFilter ==null){

mFilter = new MyFilter();

}

return mFilter;

}

class MyFilter extends Filter {

//我们在performFiltering(CharSequence charSequence)这个方法中定义过滤规则

@Override

protected FilterResults performFiltering(CharSequence charSequence) {

FilterResults result = new FilterResults();

List list;

if (TextUtils.isEmpty(charSequence)) {//当过滤的关键字为空的时候,我们则显示所有的数据

list = backList;

} else {//否则把符合条件的数据对象添加到集合中

list = new ArrayList<>();

for (Note note : backList) {

if (note.getContent().contains(charSequence)) {

list.add(note);

}

}

}

result.values = list; //将得到的集合保存到FilterResults的value变量中

result.count = list.size();//将集合的大小保存到FilterResults的count变量中

return result;

}

//在publishResults方法中告诉适配器更新界面

@Override

protected void publishResults(CharSequence charSequence, FilterResults filterResults) {

noteList = (List)filterResults.values;

if (filterResults.count>0){

notifyDataSetChanged();//通知数据发生了改变

}else {

notifyDataSetInvalidated();//通知数据失效

}

}

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OHSvPvfh-1591379236978)(data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==)]

3.设置功能(初步实现)

setting_layout.xml里面找找。

4.优化删除功能

部分删除

@Override

public boolean onOptionsItemSelected(MenuItem item){

switch (item.getItemId()){

case R.id.delete:

new AlertDialog.Builder(EditActivity.this)

.setMessage(“您确定删除吗?”)

.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

if (openMode == 4){ // new note

intent.putExtra(“mode”, -1);

setResult(RESULT_OK, intent);

}

else { // existing note

intent.putExtra(“mode”, 2);

intent.putExtra(“id”, id);

setResult(RESULT_OK, intent);

}

finish();

}

}).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dialog.dismiss();

}

}).create().show();

break;

}

return super.onOptionsItemSelected(item);

}

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Avnbc5Wd-1591379236981)(data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==)]

全部删除

@Override

public boolean onOptionsItemSelected(MenuItem item){

switch (item.getItemId()){

case R.id.menu_clear:

new AlertDialog.Builder(MainActivity.this)

.setMessage(“您确定删除全部吗?”)

.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dbHelper = new NoteDatabase(context);

SQLiteDatabase db = dbHelper.getWritableDatabase();

db.delete(“notes”, null, null);

db.execSQL(“update sqlite_sequence set seq=0 where name=‘notes’”);

refreshListView();

}

}).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dialog.dismiss();

}

}).create().show();

break;

}

return super.onOptionsItemSelected(item);

}

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-aBqCM35E-1591379236984)(data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==)]

三、后期计划


 UI美化

img

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Ox2GGctm-1591379236986)(data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==)]

学习分享

在当下这个信息共享的时代,很多资源都可以在网络上找到,只取决于你愿不愿意找或是找的方法对不对了

很多朋友不是没有资料,大多都是有几十上百个G,但是杂乱无章,不知道怎么看从哪看起,甚至是看后就忘

如果大家觉得自己在网上找的资料非常杂乱、不成体系的话,我也分享一套给大家,比较系统,我平常自己也会经常研读。

2021最新上万页的大厂面试真题

image

七大模块学习资料:如NDK模块开发、Android框架体系架构…

image

2021大厂面试真题:

image

只有系统,有方向的学习,才能在短时间内迅速提高自己的技术,只有不断地学习,不懈的努力才能拥有更好的技术,才能在互联网行业中立于不败之地。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!
料非常杂乱、不成体系的话,我也分享一套给大家,比较系统,我平常自己也会经常研读。

2021最新上万页的大厂面试真题

[外链图片转存中…(img-rVGEIXsX-1714641530898)]

七大模块学习资料:如NDK模块开发、Android框架体系架构…

[外链图片转存中…(img-yuwvIp1O-1714641530900)]

2021大厂面试真题:

[外链图片转存中…(img-Y4t3a9lf-1714641530901)]

只有系统,有方向的学习,才能在短时间内迅速提高自己的技术,只有不断地学习,不懈的努力才能拥有更好的技术,才能在互联网行业中立于不败之地。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!

  • 26
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值