Android记事本NotePad应用功能拓展(三)
一、实现功能
1.笔记分类(Note)
二、项目代码分析
1.标签类相关代码
相关类分析
SpinnerItem:分类
TagAdapterr:连接Tag数据库的适配器接口
SpinnerItem
package com.example.atry;
public class SpinnerItem {
private String tagName;
private int tagId;
public SpinnerItem(String tagName, int tagId) {
this.tagName = tagName;
this.tagId = tagId;
}
public String getTagName() {
return tagName;
}
public void setTagName(String tagName) {
this.tagName = tagName;
}
public int getTagId() {
return tagId;
}
public void setTagId(int tagId) {
this.tagId = tagId;
}
}
TagAdapter
package com.example.atry;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
public class TagAdapter extends BaseAdapter {
private Context context;
private List<String> tagList;
private List<Integer> numList;
public TagAdapter(Context context, List<String> tagList, List<Integer> numList) {
this.context = context;
this.tagList = tagList;
this.numList = numList;
}
@Override
public int getCount() {
return tagList.size();
}
@Override
public Object getItem(int position) {
return tagList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
for(int i = 0; i < numList.size(); i++) Log.d("tag", numList.get(i).toString());
Log.d("tag", "getView: " + numList.size());
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
context.setTheme((sharedPreferences.getBoolean("nightMode", false)? R.style.NightTheme: R.style.DayTheme));
View v = View.inflate(context, R.layout.tag_layout, null);
TextView blank_tag = v.findViewById(R.id.blank_tag);
TextView text_tag = v.findViewById(R.id.text_tag);
ImageView delete_tag = v.findViewById(R.id.delete_tag);
blank_tag.setText(numList.get(position).toString());
text_tag.setText(tagList.get(position));
return v;
}
}
三、参考资料
相关参考:Android记事本NotePad应用功能拓展(一)
作者GitHub下载链接:https://github.com/KangKangBigWorld/Android/tree/master/Mid_Test