工作日志记录
作者:互联网
工作日志记录7.13
上午进行学生查看试题界面的开发工作,下午学习需要深化的知识。
package fraction; import com.chinasofti.smartclassroomtv.ResourceTable; import com.chinasofti.smartclassroomtv.data.*; import ohos.aafwk.ability.fraction.Fraction; import ohos.aafwk.content.Intent; import ohos.agp.components.*; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.Date; import java.text.SimpleDateFormat; //test public class Class_history extends Fraction { private ListContainer listContainer; private Button aft; private Button pre; private int page = 1; private Text page_text; private DependentLayout history_question_frame; private DependentLayout answer_result_frame; private Button show_detials_btn; private Button close_detials_btn; List<Class_historyItem> list; Class_historyItemProvider class_historyItemProvider; @Override protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) { Component component=scatter.parse(ResourceTable.Layout_class_history,container,false); return component; } //显示查看详情界面 //获取此次上课记录发送的题目显示在history_question_frame上 private void show_history_question_frame(String class_history_id){ ArrayList<Answer_resultItem> answer_resultList = get_history_question(class_history_id); StemItemProvider stemItemProvider = new StemItemProvider(answer_resultList,getFractionAbility()); stemItemProvider.setHistory_question_frame(answer_result_frame); ArrayList<Text> text_list = new ArrayList<>(); text_list.add((Text) getFractionAbility().findComponentById(ResourceTable.Id_r1) ); text_list.add((Text) getFractionAbility().findComponentById(ResourceTable.Id_r2) ); text_list.add((Text) getFractionAbility().findComponentById(ResourceTable.Id_r3) ); text_list.add((Text) getFractionAbility().findComponentById(ResourceTable.Id_r4) ); text_list.add((Text) getFractionAbility().findComponentById(ResourceTable.Id_r5) ); stemItemProvider.setText_list(text_list); ListContainer history_question_listContainer = (ListContainer) getFractionAbility().findComponentById(ResourceTable.Id_list_history_question); history_question_listContainer.setItemProvider(stemItemProvider); history_question_frame.setVisibility(0); } //关闭查看详情界面 private void close_history_question_frame(){ history_question_frame.setVisibility(1); close_answer_result(); } //关闭答题结果界面 private void close_answer_result(){ answer_result_frame.setVisibility(1); } @Override protected void onStart(Intent intent) { super.onStart(intent); //获取上课历史并加载一页到前端UI listContainer = (ListContainer) getFractionAbility().findComponentById(ResourceTable.Id_list_class_history); list = getData(page); class_historyItemProvider = new Class_historyItemProvider(getPageData(page), getFractionAbility()); listContainer.setItemProvider(class_historyItemProvider); //设置查看细节功能 setShow_detials_setting(); //设置翻页功能 turn_page_setting(); //设置答题结果功能 answer_result_setting(); //设置搜索相关功能 search_setting(); } //设置搜索相关功能 private void search_setting(){ //点击筛选后 Button btn_search = (Button) getFractionAbility().findComponentById(ResourceTable.Id_btn_search); btn_search.setClickedListener(lis->{ String year = ((Text) getFractionAbility().findComponentById(ResourceTable.Id_year_select_text)).getText(); String month = ((Text) getFractionAbility().findComponentById(ResourceTable.Id_month_select_text)).getText(); if (Integer.parseInt(month)<10) month = "0"+month; String day = ((Text) getFractionAbility().findComponentById(ResourceTable.Id_day_select_text)).getText(); if (Integer.parseInt(day)<10) day = "0"+day; String date = year+"-"+month+"-"+day; List<Class_historyItem> interList = new ArrayList<>();; for (int i=0;i<list.size();i++){ if(list.get(i).getTime().equals(date)) interList.add(list.get(i)); } class_historyItemProvider = new Class_historyItemProvider(interList, getFractionAbility()); listContainer.setItemProvider(class_historyItemProvider); }); //点击返回后 Button btn_return = (Button) getFractionAbility().findComponentById(ResourceTable.Id_btn_return); btn_return.setClickedListener(lis->{ class_historyItemProvider = new Class_historyItemProvider(getPageData(page), getFractionAbility()); listContainer.setItemProvider(class_historyItemProvider); }); //年 Button year_up = (Button) getFractionAbility().findComponentById(ResourceTable.Id_year_up); year_up.setClickedListener(lis->{ Text year_select_text = (Text) getFractionAbility().findComponentById(ResourceTable.Id_year_select_text); if (year_select_text.getText().equals("2021")) return; year_select_text.setText(Integer.parseInt(year_select_text.getText())+1+""); }); Button year_down = (Button) getFractionAbility().findComponentById(ResourceTable.Id_year_down); year_down.setClickedListener(lis->{ Text year_select_text = (Text) getFractionAbility().findComponentById(ResourceTable.Id_year_select_text); if (year_select_text.getText().equals("2011")) return; year_select_text.setText(Integer.parseInt(year_select_text.getText())-1+""); }); //月 Button month_up = (Button) getFractionAbility().findComponentById(ResourceTable.Id_month_up); month_up.setClickedListener(lis->{ Text month_select_text = (Text) getFractionAbility().findComponentById(ResourceTable.Id_month_select_text); if (month_select_text.getText().equals("12")) return; month_select_text.setText(Integer.parseInt(month_select_text.getText())+1+""); }); Button month_down = (Button) getFractionAbility().findComponentById(ResourceTable.Id_month_down); month_down.setClickedListener(lis->{ Text month_select_text = (Text) getFractionAbility().findComponentById(ResourceTable.Id_month_select_text); if (month_select_text.getText().equals("1")) return; month_select_text.setText(Integer.parseInt(month_select_text.getText())-1+""); }); //天 Button day_up = (Button) getFractionAbility().findComponentById(ResourceTable.Id_day_up); day_up.setClickedListener(lis->{ Text day_select_text = (Text) getFractionAbility().findComponentById(ResourceTable.Id_day_select_text); if (day_select_text.getText().equals("31")) return; day_select_text.setText(Integer.parseInt(day_select_text.getText())+1+""); }); Button day_down = (Button) getFractionAbility().findComponentById(ResourceTable.Id_day_down); day_down.setClickedListener(lis->{ Text day_select_text = (Text) getFractionAbility().findComponentById(ResourceTable.Id_day_select_text); if (day_select_text.getText().equals("1")) return; day_select_text.setText(Integer.parseInt(day_select_text.getText())-1+""); }); } //设置查看细节功能 private void setShow_detials_setting(){ history_question_frame = (DependentLayout) getFractionAbility().findComponentById(ResourceTable.Id_history_question_frame); show_detials_btn = (Button) getFractionAbility().findComponentById(ResourceTable.Id_details); show_detials_btn.setClickedListener(lis->{ int len = (Math.min(list.size(),page*14) - (page-1)*14); int count = 0; int key = 0; for (int i = 0; i< len ; i++ ){ Checkbox cb = (Checkbox) listContainer.getComponentAt(i).findComponentById(ResourceTable.Id_item_name); if (cb.isChecked()){ key = i + (page-1)*14; count++; } } if (count!=1) return; show_history_question_frame(list.get(key).getId()); }); close_detials_btn = (Button) getFractionAbility().findComponentById(ResourceTable.Id_cancle); close_detials_btn.setClickedListener(lis->{ close_history_question_frame(); }); } //设置翻页功能 private void turn_page_setting(){ page_text = (Text) getFractionAbility().findComponentById(ResourceTable.Id_page); page_text.setText(""+page); aft = (Button) getFractionAbility().findComponentById(ResourceTable.Id_aft); aft.setClickedListener(lis->{ if ((page)*14 >= list.size()) return; class_historyItemProvider = new Class_historyItemProvider(getPageData(++page), getFractionAbility()); listContainer.setItemProvider(class_historyItemProvider); page_text.setText(""+page); }); pre = (Button) getFractionAbility().findComponentById(ResourceTable.Id_pre); pre.setClickedListener(lis->{ if (page<=1) return; class_historyItemProvider = new Class_historyItemProvider(getPageData(--page), getFractionAbility()); listContainer.setItemProvider(class_historyItemProvider); page_text.setText(""+page); }); } //设置答题结果功能 private void answer_result_setting(){ answer_result_frame = (DependentLayout) getFractionAbility().findComponentById(ResourceTable.Id_answer_result_frame); Button answer_close = (Button) getFractionAbility().findComponentById(ResourceTable.Id_answer_close); answer_close.setClickedListener(lis->{ close_answer_result(); }); } //从后端数据库获取指定上课记录的发送题目列表 用class_history_id在数据库查询 //题目基本信息 题型 题干 分值 //答题情况 回答人数 正确人数 正确率 private ArrayList<Answer_resultItem> get_history_question(String class_history_id) { ArrayList<Answer_resultItem> list = new ArrayList<>(); for (int i = 1; i <= 4; i++) { list.add(new Answer_resultItem("单选题","题干"+i,"1","50","30","60%")); } return list; } //从后端数据库获得所有上课历史信息,保存到list private ArrayList<Class_historyItem> getData(int page) { ArrayList<Class_historyItem> list = new ArrayList<>(); for (int i = 1; i <= 45; i++) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式 Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.add(Calendar.DATE, 0-i); //日期格式是yyyy-mm-dd list.add(new Class_historyItem(df.format(calendar.getTime()),"id"+i,"备注"+i)); } return list; } //从list获取一页的上课历史信息,不连接后端 private ArrayList<Class_historyItem> getPageData(int page) { ArrayList<Class_historyItem> list2 = new ArrayList<>(); for (int i = (page-1)*14; i < Math.min(list.size(),page*14); i++) { list2.add(list.get(i)); } return list2; } }
标签:记录,text,findComponentById,工作,select,日志,Id,getFractionAbility,ResourceTable 来源: https://blog.csdn.net/ht1614423953/article/details/118873283