Android——待办事项(ToDoList)

  • 简述
  • 数据插入
    • 布局效果图
    • 布局代码
    • 显示
    • 效果图
    • 布局代码
  • 数据库
    • 实体类
    • 建表
    • CRUD
      • 适配器
    • Lunar类(用于日历的阳历和阴历转换)

简述

一:实现功能
1:创建待办事项的显示与完成待办事项时的显示
2:搜索已经存在的代办事项
3:日历(阳历阴历转换)

数据插入

public class MainActivity extends AppCompatActivity {private Button EXEInout, EXESearch;private Button btn_List,btn_Calendar,btn_Complete;private static EditText InputContent, SearchContent,SerialNumber,SearchSerialNumber;private static EditText GetContent,GetSerialNumber,GetContent1,GetSerialNumber1,GetContent2,GetSerialNumber2;private CheckBox checkBox,checkBox1,checkBox2;public static int count = 1;public static String ID = null;public static String Content = null;Dao dao = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);EXEInout = (Button) findViewById(R.id.exeInput);EXESearch = (Button) findViewById(R.id.exeSearch);btn_Complete = (Button) findViewById(R.id.Complete);btn_List = (Button) findViewById(R.id.List);btn_Calendar = (Button) findViewById(R.id.Calendar);GetContent = (EditText) findViewById(R.id.GetContent);GetSerialNumber = (EditText) findViewById(R.id.GetSerialNumber);//序号GetContent1 = (EditText) findViewById(R.id.GetContent1);GetSerialNumber1 = (EditText) findViewById(R.id.GetSerialNumber1);//序号GetContent2 = (EditText) findViewById(R.id.GetContent2);GetSerialNumber2 = (EditText) findViewById(R.id.GetSerialNumber2);//序号SerialNumber = (EditText) findViewById(R.id.SerialNumber);checkBox = (CheckBox) findViewById(R.id.checkbox);checkBox1 = (CheckBox) findViewById(R.id.checkbox1);checkBox2 = (CheckBox) findViewById(R.id.checkbox2);InputContent = (EditText) findViewById(R.id.inputContent);SearchContent = (EditText) findViewById(R.id.SearchContent);SearchSerialNumber = (EditText) findViewById(R.id.SearchSerialNumber);//用于查找待办事项EXESearch.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {dao = new Dao(MainActivity.this);String SearchID = SearchSerialNumber.getText().toString();String Content = dao.Query(SearchID);SearchContent.setText(Content);}});//用于添加待办事项EXEInout.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {dao = new Dao(MainActivity.this);ID = SerialNumber.getText().toString();Content = InputContent.getText().toString();if (ID.equals("") && Content.equals("")){Toast.makeText(MainActivity.this,"输入的待办事项不能为空",Toast.LENGTH_SHORT).show();return ;}dao.Insert(new DataBase(ID,Content));if (count == 1) {GetSerialNumber.setVisibility(View.VISIBLE);GetContent.setVisibility(View.VISIBLE);checkBox.setVisibility(View.VISIBLE);//可见GetSerialNumber.setText(ID);GetContent.setText(Content);}if (count == 2){GetSerialNumber1.setVisibility(View.VISIBLE);GetContent1.setVisibility(View.VISIBLE);checkBox1.setVisibility(View.VISIBLE);//可见GetSerialNumber1.setText(ID);GetContent1.setText(Content);}if (count == 3){GetSerialNumber2.setVisibility(View.VISIBLE);GetContent2.setVisibility(View.VISIBLE);checkBox2.setVisibility(View.VISIBLE);//可见GetSerialNumber2.setText(ID);GetContent2.setText(Content);}count++;if (count > 3)Toast.makeText(MainActivity.this,"待办事项存在太多了,请做完一些在添加吧!",Toast.LENGTH_SHORT).show();Log.d("Count",count+"");Log.d(Dao.TAG,ID);Log.d(Dao.TAG,Content);//清除数据库专用//for (int i = 0; i< 50;i++)//dao.Delete(i+"");// setListen();}});//(可见不可见占位置,只是消失,隐藏不会占据屏幕位置)//如果被选择就使checkbox,序号,EditText三个为隐藏,并传到另一个一个页面//用于提交待办事项(表示已完成)btn_Complete.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = null;switch (JudgeCheckBoxStatus()) {case 1:GetContent.setVisibility(View.GONE);GetSerialNumber.setVisibility(View.GONE);checkBox.setVisibility(View.GONE);count--;//完成一件待办事项,减少一次计数,方便下一次添加待办事项intent = new Intent(MainActivity.this, Completed.class);break;case 2:GetContent1.setVisibility(View.GONE);GetSerialNumber1.setVisibility(View.GONE);checkBox1.setVisibility(View.GONE);count--;//完成一件待办事项,减少一次计数,方便下一次添加待办事项intent = new Intent(MainActivity.this, Completed.class);break;case 3:GetContent2.setVisibility(View.GONE);GetSerialNumber2.setVisibility(View.GONE);checkBox2.setVisibility(View.GONE);count--;//完成一件待办事项,减少一次计数,方便下一次添加待办事项intent = new Intent(MainActivity.this, Completed.class);break;}startActivity(intent);}});//跳转到日历视图btn_Calendar.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = null;intent = new Intent(MainActivity.this, CalendarDemo.class);startActivity(intent);}});}//用于判断是否已经完成,存在漏洞int  JudgeCheckBoxStatus(){if (checkBox.isChecked() == true){return 1;}if (checkBox1.isChecked() == true){return 2;}if (checkBox2.isChecked() == true){return 3;}return 0;}}

布局效果图

布局代码

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><ImageViewandroid:id="@+id/add"android:layout_height="30dp"android:layout_width="30dp"android:background="@drawable/add"android:layout_marginTop="7dp"/><EditTextandroid:id="@+id/SerialNumber"android:layout_marginLeft="30dp"android:layout_width="30dp"android:layout_height="wrap_content"/><EditTextandroid:id="@+id/inputContent"android:layout_marginLeft="60dp"android:layout_width="280dp"android:layout_height="wrap_content"android:hint="输入待办事项..."/><Buttonandroid:id="@+id/exeInput"android:layout_height="40dp"android:layout_width="40dp"android:background="@drawable/arrowrightcircle"android:layout_marginTop="7dp"android:layout_toRightOf="@+id/inputContent"android:layout_marginLeft="20dp"/><ImageViewandroid:id="@+id/Search"android:layout_height="30dp"android:layout_width="30dp"android:background="@drawable/search"android:layout_marginTop="50dp"android:layout_below="@+id/add"/><EditTextandroid:id="@+id/SearchSerialNumber"android:layout_marginLeft="30dp"android:layout_width="30dp"android:layout_height="wrap_content"android:layout_below="@id/SerialNumber"android:layout_marginTop="32dp"/><EditTextandroid:id="@+id/SearchContent"android:layout_marginLeft="60dp"android:layout_width="280dp"android:layout_height="wrap_content"android:hint="搜索待办事项..."android:layout_below="@+id/inputContent"android:layout_marginTop="32dp"/><Buttonandroid:id="@+id/exeSearch"android:layout_height="40dp"android:layout_width="40dp"android:background="@drawable/arrowrightcircle"android:layout_marginTop="32dp"android:layout_toRightOf="@+id/inputContent"android:layout_marginLeft="20dp"android:layout_below="@+id/exeInput"/><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="25dp"android:textAllCaps="false"android:text="----------------全部----------------"android:textSize="20sp"android:gravity="center"android:layout_below="@+id/SearchContent"/><CheckBoxandroid:id="@+id/checkbox"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="0dp"android:layout_marginTop="105dp"android:visibility="invisible"android:layout_below="@id/Search"/><EditTextandroid:id="@+id/GetSerialNumber"android:layout_height="wrap_content"android:layout_width="40dp"android:text=""android:layout_marginLeft="40dp"android:layout_marginTop="85dp"android:textSize="25sp"android:visibility="invisible"android:layout_below="@+id/SearchContent"/><EditTextandroid:id="@+id/GetContent"android:layout_width="match_parent"android:layout_height="wrap_content"android:text=""android:textSize="25sp"android:layout_marginTop="86dp"android:layout_marginLeft="80dp"android:visibility="invisible"android:layout_below="@+id/exeSearch"/><CheckBoxandroid:id="@+id/checkbox1"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="0dp"android:layout_marginTop="50dp"android:visibility="invisible"android:layout_below="@id/checkbox"/><EditTextandroid:id="@+id/GetSerialNumber1"android:layout_height="wrap_content"android:layout_width="40dp"android:text=""android:layout_marginLeft="40dp"android:layout_marginTop="20dp"android:textSize="25sp"android:visibility="invisible"android:layout_below="@+id/GetSerialNumber"/><EditTextandroid:id="@+id/GetContent1"android:layout_width="match_parent"android:layout_height="wrap_content"android:text=""android:textSize="25sp"android:layout_marginTop="20dp"android:layout_marginLeft="80dp"android:visibility="invisible"android:layout_below="@+id/GetContent"/><CheckBoxandroid:id="@+id/checkbox2"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="0dp"android:layout_marginTop="50dp"android:visibility="invisible"android:layout_below="@id/checkbox1"/><EditTextandroid:id="@+id/GetSerialNumber2"android:layout_height="wrap_content"android:layout_width="40dp"android:text=""android:layout_marginLeft="40dp"android:layout_marginTop="20dp"android:textSize="25sp"android:visibility="invisible"android:layout_below="@+id/GetSerialNumber1"/><EditTextandroid:id="@+id/GetContent2"android:layout_width="match_parent"android:layout_height="wrap_content"android:text=""android:textSize="25sp"android:layout_marginTop="22dp"android:layout_marginLeft="80dp"android:visibility="invisible"android:layout_below="@+id/GetContent1"/><Buttonandroid:id="@+id/List"android:layout_height="50dp"android:layout_width="120dp"android:text="List"android:textAllCaps="false"android:layout_marginTop="500dp"android:layout_alignParentLeft="true"/><Buttonandroid:id="@+id/Complete"android:layout_height="50dp"android:layout_width="120dp"android:layout_marginLeft="150dp"android:text="Complete"android:textAllCaps="false"android:layout_marginTop="90dp"android:layout_below="@+id/GetContent2"/><Buttonandroid:id="@+id/Calendar"android:layout_height="50dp"android:layout_width="120dp"android:text="Calendar"android:textAllCaps="false"android:layout_marginTop="500dp"android:layout_alignParentRight="true"/></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"></RelativeLayout></LinearLayout>

显示

 public class Completed extends AppCompatActivity {private Button btn_Receive;private RecyclerView recyclerView;private List<DataBase> dataBaseList = new ArrayList<>();private MyRecyclerView myRecyclerView;private DataBase dataBase;private TextView Title;private int count = 1;Dao dao = null;private  String GetContent = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_completed);Title = (TextView) findViewById(R.id.Title);recyclerView = (RecyclerView) findViewById(R.id.RecyclerViewItem);btn_Receive = (Button) findViewById(R.id.EXE_Receive);//设置布局管理器LinearLayoutManager layoutManager = new LinearLayoutManager(Completed.this);recyclerView.setLayoutManager(layoutManager);//设置适配器myRecyclerView = new MyRecyclerView(dataBaseList);recyclerView.setAdapter(myRecyclerView);btn_Receive.setOnClickListener(new Button.OnClickListener() {DataBase dataBase = new DataBase();@Overridepublic void onClick(View v) {String CompletedID = MainActivity.ID;String CompletedContent = MainActivity.Content;if (! ("".equals(CompletedID)) && ( "".equals(CompletedContent))){Toast.makeText(Completed.this,"内容不能为空",Toast.LENGTH_SHORT).show();}else {dataBase = new DataBase(CompletedID, CompletedContent);//获取实例dataBaseList.add(dataBase);//添加数据myRecyclerView.notifyItemChanged(dataBaseList.size() - 1);recyclerView.scrollToPosition(dataBaseList.size() - 1);}}});}

效果图

布局代码

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><TextViewandroid:id="@+id/Title"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="已完成事项"android:textSize="25sp"android:gravity="center"android:textColor="#090909"android:layout_marginBottom="20dp"/><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/RecyclerViewItem"android:layout_width="match_parent"android:layout_height="wrap_content"/><Buttonandroid:id="@+id/EXE_Receive"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="EXE_Receive"android:textAllCaps="false"android:layout_marginTop="20dp"/></LinearLayout>

数据库

实体类

public class DataBase {private String id;private String Content;private static final int Check = 1;//用于判断状态待办事项是否已经完成private static final int NotCheck = 0;public String getId() {return id;}public String getContent() {return Content;}public DataBase() {super();}public DataBase(String id, String Content) {super();this.id = id;this.Content = Content;}}

建表

public class Helper extends SQLiteOpenHelper {public static final String TableName = "ToDoList";public static final String ID = "ID";public static final String Content = "Content";private static final String DataBase = "todolist.db";private static final SQLiteDatabase.CursorFactory Factory = null;public static final int version = 1;public Helper(@Nullable Context context) {super(context, DataBase, Factory, version);}@Overridepublic void onCreate(SQLiteDatabase db) {// 操作数据库String sql = "create table " + TableName + "("+ID+" varchar(20) primary key, "+Content+" varchar(20));";db.execSQL(sql);}@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {db.execSQL("drop table if exists "+TableName);onCreate(db);}
}

CRUD

public class Dao {public static final String TAG = "DataBase";private Helper helper ;private SQLiteDatabase DB;public Dao(Context context){helper = new Helper(context);}public void Insert(DataBase dataBase){DB = helper.getReadableDatabase();if (DB.isOpen()){ContentValues values = new ContentValues();values.put(Helper.ID,dataBase.getId());values.put(Helper.Content,dataBase.getContent());long RowId = DB.insert(Helper.TableName,null,values);if(RowId == -1)Log.i(TAG, "数据插入失败!");elseLog.i(TAG, "数据插入成功!"+RowId);}}//根据序号删除数据//当前id为暂不为序号public void Delete(String id){DB = helper.getReadableDatabase();if (DB.isOpen()){String whereClause = "ID = ?";String[] whereArgs = {id + ""};int count = DB.delete(Helper.TableName, whereClause, whereArgs);if (count > 0)Log.i(TAG, "删除了: " + count + "行");elseLog.i("todolist", "数据未删除!");DB.close(); // 数据库关闭}}public void Update(String id ,String Content){DB = helper.getWritableDatabase();if(DB.isOpen()) {   // 如果数据库打开, 执行添加的操作ContentValues values = new ContentValues();values.put("ID",id);values.put("Content", Content);int count  = DB.update(Helper.TableName, values, "_ID = ?", new String[]{id + ""});if (count > 0)Log.i(TAG, "修改了: " + count + "行");elseLog.i("todolist", "数据未删除!");DB.close(); // 数据库关闭}}public String Query(String id){DB = helper.getReadableDatabase();//selection查询子句的条件,可以使用主键查询String[] columns = {"ID", "Content"};  // 需要的列String selection = "ID = ?";String[] selectionArgs = {id + ""};Cursor cursor = DB.query(Helper.TableName,columns,selection,selectionArgs,null,null,null);if (cursor.moveToFirst()){if(cursor != null && cursor.moveToFirst()) {//String _id = cursor.getString(0);String Content = cursor.getString(1);DB.close();return Content;}cursor.close();DB.close();}return null;}public List<DataBase> QueryAll() {DB = helper.getReadableDatabase();  // 获得一个只读的数据库对象if(DB.isOpen()) {String[] columns = {"ID", "Content"};  // 需要的列String selection = null;    // 选择条件, 给null查询所有String[] selectionArgs = null;  // 选择条件的参数, 会把选择条件中的? 替换成数据中的值String groupBy = null;  // 分组语句  group by nameString having = null;   // 过滤语句String orderBy = null;  // 排序Cursor cursor = DB.query(Helper.TableName, columns, selection, selectionArgs, groupBy, having, orderBy);String id;String Content;if(cursor != null && cursor.getCount() > 0) {List<DataBase> DataBaseList = new ArrayList<DataBase>();while(cursor.moveToNext()) {    // 向下移一位, 知道最后一位, 不可以往下移动了, 停止.id = cursor.getString(0);Content = cursor.getString(1);DataBaseList.add(new DataBase(id, Content));}DB.close();return DataBaseList;}DB.close();}return null;}
}

适配器

//使用此类必须先导入闭包implementation 'com.android.support:recyclerview-v7:27.1.1'(闭包版本很多)
public class MyRecyclerView extends RecyclerView.Adapter<MyRecyclerView.ViewHolder> {private List<DataBase> DataBaseList;public MyRecyclerView (List<DataBase> DataBaseList){this.DataBaseList = DataBaseList;}@NonNull@Override//获取布局public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_item,parent,false);return new ViewHolder(view);}//给子控件赋值@Overridepublic void onBindViewHolder(@NonNull ViewHolder holder, int position) {DataBase dataBase = DataBaseList.get(position);holder.checkBox.setChecked(true);//设置勾选holder.SearchSerialNumber.setText(dataBase.getId());//设置完成待办事项的序号holder.Content.setText(dataBase.getContent());//设置完成待办事项的内容}@Overridepublic int getItemCount() {return DataBaseList.size();}static class ViewHolder extends RecyclerView.ViewHolder {CheckBox checkBox;EditText SearchSerialNumber,Content;public ViewHolder(@NonNull View itemView) {super(itemView);checkBox = (CheckBox) itemView.findViewById(R.id.RecyclerViewCheckbox);SearchSerialNumber = (EditText) itemView.findViewById(R.id.RecyclerViewSerialNumber);Content = (EditText) itemView.findViewById(R.id.RecyclerViewContent);}}
}

Lunar类(用于日历的阳历和阴历转换)

public class Lunar {private final int year;private final int month;private final int day;private boolean leap;//阴历月份表示形式final static String[] LunarMonthStyle = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};@SuppressLint("SimpleDateFormat")static SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy年MM月dd日");final static long[] lunarInfo = new long[]{0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2,0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977,0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970,0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950,0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557,0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0,0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0,0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6,0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570,0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0,0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5,0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930,0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530,0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45,0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0};//====== 传回农历 y年的总天数final private static int yearDays(int y) {int i, sum = 348;for (i = 0x8000; i > 0x8; i >>= 1) {if ((lunarInfo[y - 1900] & i) != 0)sum += 1;}return (sum + leapDays(y));}//====== 传回农历 y年闰月的天数final private static int leapDays(int y) {if (leapMonth(y) != 0) {if ((lunarInfo[y - 1900] & 0x10000) != 0)return 30;elsereturn 29;} elsereturn 0;}//====== 传回农历 y年闰哪个月 1-12 , 没闰传回 0final private static int leapMonth(int y) {return (int) (lunarInfo[y - 1900] & 0xf);}//====== 传回农历 y年m月的总天数final private static int monthDays(int y, int m) {if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)return 29;elsereturn 30;}//====== 传回农历 y年的生肖final public String animalsYear() {final String[] Animals = new String[]{"鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"};return Animals[(year - 4) % 12];}//====== 传入 月日的offset 传回干支, 0=甲子final private static String cyclicalm(int num) {final String[] TianGan = new String[]{"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"};final String[] JiaZi = new String[]{"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"};return (TianGan[num % 10] + JiaZi[num % 12]);}//====== 传入 offset 传回干支, 0=甲子final public String cyclical() {int num = year - 1900 + 36;return (cyclicalm(num));}public String getLunarMonthString() {// TODO Auto-generated method stubreturn null;}public Lunar(Calendar cal) {@SuppressWarnings("unused") int yearCyl, monCyl, dayCyl;int leapMonth = 0;Date baseDate = null;try {baseDate = chineseDateFormat.parse("1900年1月31日");} catch (ParseException e) {e.printStackTrace(); //To change body of catch statement use Options | File Templates.}//求出和1900年1月31日相差的天数assert baseDate != null;int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()) / 86400000L);dayCyl = offset + 40;monCyl = 14;//用offset减去每农历年的天数// 计算当天是农历第几天//i最终结果是农历的年份//offset是当年的第几天int iYear, daysOfYear = 0;for (iYear = 1900; iYear < 2050 && offset > 0; iYear++) {daysOfYear = yearDays(iYear);offset -= daysOfYear;monCyl += 12;}if (offset < 0) {offset += daysOfYear;iYear--;monCyl -= 12;}//农历年份year = iYear;yearCyl = iYear - 1864;leapMonth = leapMonth(iYear); //闰哪个月,1-12leap = false;//用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天int iMonth, daysOfMonth = 0;for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) {//闰月if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) {--iMonth;leap = true;daysOfMonth = leapDays(year);} elsedaysOfMonth = monthDays(year, iMonth);offset -= daysOfMonth;//解除闰月if (leap && iMonth == (leapMonth + 1)) leap = false;if (!leap) monCyl++;}//offset为0时,并且刚才计算的月份是闰月,要校正if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) {if (leap) {leap = false;} else {leap = true;--iMonth;--monCyl;}}//offset小于0时,也要校正if (offset < 0) {offset += daysOfMonth;--iMonth;--monCyl;}month = iMonth;day = offset + 1;}public static String getChinaDayString(int day) {String[] chineseTen = {"初", "十", "廿", "三"};int n = day % 10 == 0 ? 9 : day % 10 - 1;if (day > 30)return "";if (day == 10)return "初十";elsereturn chineseTen[day / 10] + LunarMonthStyle[n];}public String toString() {return (leap ? "闰" : "") + LunarMonthStyle[month - 1] + "月" + getChinaDayString(day);}
}

Android——待办事项(ToDoList)相关推荐

  1. android+待办事项+日历,TickTick Pro「滴答清单」v5.9.4.4 for Android 直装解锁高级版 —— 一个强大的待办事项和任务管理应用...

    TickTick Pro「滴答清单」是一个强大的待办事项和任务管理应用,它可以在您的所有设备上进行无缝云端同步.无论是计划行程.做备忘录.与家庭成员分享购物清单还是与您的同事协作,TickTick 都 ...

  2. 从零开始写一个Android待办事项ToDoListApp

    概述 初衷 作为一个程序员,每天要处理的事项越来越多,有时一件事情花费了太多的时间而忽略了还有其他事情等着处理.开始是借助Microsoft ToDo 来记录下待办事项,时不时的去看一下,勾选掉已经完 ...

  3. 适用于Android的最佳免费待办事项列表应用程序以及如何使自己成才

    如果您没有组织任务,那么跟踪任务可能会很麻烦. 这就是待办事项清单的帮助. 在这篇文章中,我将向您展示一些适用于Android的最佳免费待办事项列表应用程序. 然后,我将为您提供一些有关如何创建自己的 ...

  4. android room_Android Room –待办事项清单应用程序

    android room In this tutorial, we'll be discussing and implementing the Room library introduced by G ...

  5. 鸿蒙开发-从搭建todolist待办事项来学习组件与js之间的交互

    场景 鸿蒙开发-实现页面跳转与页面返回: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/118383025 在上面实现从主页面跳转 ...

  6. 用jQuery--实现todolist待办事项清单

    效果图 实现todolist整体思路: 思路图如果看着不方便 js代码里面已经做好详细注释 html代码 <!DOCTYPE html> <html><head>& ...

  7. vue实现ToDoList待办事项/清单

    1.这个功能运用的知识点比较多,computed计算,watch监听,directives自定义指令和methods定义事件,还有一些属性绑定,列表渲染,表单绑定指令,按键修饰符,表单修饰符等... ...

  8. ToDoList—最简单的待办事项列表(经典案例)重点

    代码运行结果 案例说明 案例分析 案例实现代码 tdlist.html代码 <!DOCTYPE html> <html><head><meta http-eq ...

  9. 基于Vue的新拟态ToDoList(待办事项添加)

    简介 基于Vue半全家桶的新拟态板ToDoList(点击访问在线地址),一个todolist而已,用几乎Vue全家桶是不是有点小题大做,是的,必须的,因为要巩固的知识,并且功能也相应的增加了,你可以打 ...

最新文章

  1. 固态器件理论(10)半导体制造技术
  2. 2019牛客提前批一血:猝不及防的java实习面经
  3. Cinder 组件详解 - 每天5分钟玩转 OpenStack(47)
  4. dotnet-httpie 0.2.0 Released
  5. CloudIDE:为开发者写代码开启“加速”模式
  6. Firefox Javascript引擎变成单线程
  7. 美国本科申请Essay的写作注意事项
  8. python mongodb_python实现mongodb的增删改查
  9. 虚拟串口服务器怎manager,VSPManager虚拟串口管理软件
  10. 卸载IE11并恢复到IE9
  11. 计算机网络原理(04741)第1章:计算机网络概述
  12. mysql查看mylog命令_mysql 日志查询(查看mysql日志命令)
  13. 计算机软件系统崩溃,电脑软件打开后闪退或崩溃怎么办
  14. 筑梦数字时代,城链科技战略峰会西安站顺利落幕
  15. Transformer for image quality assessment阅读笔记
  16. 数据结构之链表(LinkedList详解)
  17. android开源项目---View篇
  18. Flood---ZJFC Weekly - 5
  19. 她力量系列六丨杨笛一:女孩长大后数理化可以很好,科研可以很鲜活
  20. RK3568、RK3588、RK3358性能介绍及表格差异性对比整理

热门文章

  1. 微信小程序盲盒系统源码 附带教程
  2. 美国通胀“爆表”要加息100点?
  3. 日语语法笔记【翻译】
  4. getTime()方法在苹果系统的bug
  5. Visual Studio(VS) Code详解
  6. Windows Server 2016搭建文件服务器
  7. 事务机制:Redis能实现ACID属性吗?
  8. 一文梳理 | 电力企业网络安全管理及等级保护工作重点
  9. 什么叫幂等?如何实现幂等性?
  10. Qt中提示“常量中有换行符“的解决方法