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==)]
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
最后
在此为大家准备了四节优质的Android高级进阶视频:
架构师项目实战——全球首批Android开发者对Android架构的见解
附相关架构及资料
笔记、源码讲义、实战项目、讲解视频**
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
[外链图片转存中…(img-4JEWZkBS-1711376117220)]
最后
在此为大家准备了四节优质的Android高级进阶视频:
架构师项目实战——全球首批Android开发者对Android架构的见解
附相关架构及资料
[外链图片转存中…(img-NU09MeRW-1711376117220)]
领取获取往期Android高级架构资料、源码、笔记、视频。高级UI、性能优化、架构师课程、NDK、混合式开发(ReactNative+Weex)微信小程序、Flutter全方面的Android进阶实践技术,群内还有技术大牛一起讨论交流解决问题。