android实现单词测试功能,android项目实战-背呗单词DEV07-单词测试实现(示例代码)...

该篇说明

该篇我们进行单词测试实现讲解

也就是单词测试界面WordExamActivity中功能

布局也需要在xml中实现

但是也需要有单词测试视图类来设置一些值具体查看对照源码

在该界面中,测试完后会更新数据

效果如图

f4b5ee5989cb52a72fb7d831f59a090b.gif

流程图

1bf61808d0331c05ea9a4e055e03d2c8.png

单词测试界面功能流程详解

1>显示单词测试信息

a> 首先要加载单词测试数据

需要调用单词测试管理模块加载数据功能

private voidloadWordExamData() {

loadingExamDataProgressBar=(ProgressBar)

findViewById(R.id.loadingExamDataProgressBar);

loadingExamDataProgressBar.setVisibility(View.VISIBLE);newThread() {public voidrun() {newWordExamManager().loadData();

SystemUtil.sleepvd(2000);

myHandler.sendEmptyMessage(0);

}

}.start();

}

b> handler处理0的消息并初始及处理逻辑

@SuppressLint("HandlerLeak")private voidinitHandler() {

myHandler= newHandler() {public voidhandleMessage(android.os.Message msg) {switch(msg.what) {case 0:

wordExamLinearLayout.setVisibility(View.VISIBLE);

loadingExamDataProgressBar.setVisibility(View.GONE);

init();

logic();break;

}

}

};

}

c> 接着在初始中加载显示单词测试界面

private voidloadView() {//正确选项随机数Global.rightOptionRandom= Math.floor(Math.random() * 4 + 1);

WordDet wordDet= Global.wordDetList.get(Global.studyedWordId - 1);//单词测试标题wordExamTitelTextView.setText(wordDet.wordStr+ String.format(" /%s/", wordDet.pron));

WordExamView.initOptions(this);

WordExamView.setOptionsData(wordDet);

}

2>四个选项添加监听

来实现点击判断选择的正确还是错误。进一步确定执行

监听类请自行查看源码

private voidlogic() {for(int i=1; i<=4; i++) {

LinearLayout wordExamOptionll= WordExamView.weOptionLLayoutList.get(i-1);

wordExamOptionll.setOnClickListener(newWordExamOptionClickListener(wordExamOptionll, i));

}

}

3>测试正确后下一个

a> 跳转下一个

单选正确后自动跳转到下一个

如果是已是最后一个,那么更新数据

public voidexamNext() {

Global.studyedWordId+= 1;if(Global.studyedWordId <=Global.wordList.size()) {

timer.schedule(newTimerTask() {

@Overridepublic voidrun() {

myHandler.sendEmptyMessage(1);

}

},1000);

}else if((Global.studyedWordId >Global.wordList.size())) {

updateData();

}

}

b> 使用计时器控制1秒后跳转

Handler异步任务处理1的消息测试下个单词

@SuppressLint("HandlerLeak")private voidinitHandler() {

myHandler= newHandler() {public voidhandleMessage(android.os.Message msg) {switch(msg.what) {case 1:if(timer != null) {

timer.cancel();

}

timer= newTimer();

showNextView();break;

}

}

};

}

c> 更新数据

如果测试完最后一个,就进行更新数据。

如果从单词背诵界面跳转的,才更新记录次数

private voidupdateData() {

clear();if(parentStr != null && parentStr.equals("wordDet")) {

updateDataProgressDialog.setMessage("正在更新数据");

updateDataProgressDialog.show();newThread(){

@Overridepublic voidrun() {

updateRecordTimes();

}

}.start();

}else if(parentStr.equals("wordList")) {

Toast.makeText(context,

Global.selectUnitGroupFlagStr+ "单元测组试完,回到单词列表界面!!!",

Toast.LENGTH_LONG).show();

toNextView(WordListActivity.class);

}

}

d> 更新次数

> 没有完成次数进度才可设置需要更新数据

> 如果结果记录次数等于需要背诵的次数,则返回到今天任务

进度归0(会存储到数据库),同时需要清空单词记录表及单词表

> 否则返回到单词列表,递增进度(不保存到数据库)

private voidupdateRecordTimes() {int recitedtimes =Integer.parseInt(Global.studyPlanObj.lastReciteProgressStr.split("/")[0]);int resultRtimes = 0;if(recitedtimes !=Global.defaultReciteTimes) {

resultRtimes= recitedtimes + 1;

Global.studyPlanObj.lastReciteProgressStr= resultRtimes + "/" + Global.defaultReciteTimes;if(resultRtimes ==Global.defaultReciteTimes) {newReciteManager().updateData();

SystemUtil.sleepvd(2000);

myHandler.sendEmptyMessage(2);

}else{newReciteManager().updateReciteProgress(Global.studyPlanObj.lastReciteProgressStr);

SystemUtil.sleepvd(2000);

myHandler.sendEmptyMessage(3);

}

}

}

4>测试错误后的操作

测试错误后显示按钮操作

> 返回学习按钮,返回单词列表界面进行学习

> 继续测试按钮,重新开始测试

public voidshowButtonAfterNotRight() {

returnToStudyButton.setVisibility(View.VISIBLE);

continueExamButton.setVisibility(View.VISIBLE);

returnToStudyButton.setOnClickListener(newOnClickListener() {

@Overridepublic voidonClick(View v) {

clear();

toNextView(WordListActivity.class);

}

});

continueExamButton.setOnClickListener(newOnClickListener() {

@Overridepublic voidonClick(View v) {

Global.studyedWordId= 1;

Global.examedWordId= 1;

returnToStudyButton.setVisibility(View.GONE);

continueExamButton.setVisibility(View.GONE);

showNextView();

}

});

}

单词测试后台功能详解

在加载数据以及更新次数方法使用到了后台模块

使用到了如下模块功能

> 单词测试管理WordExamManager的加载数据loadData()方法

> 背诵管理ReciteManager的更新背诵次数updateReciteProgress()方法

1>单词测试管理加载数据详解

a> 首先是加载数据方法

public voidloadData() {if(Global.examWordDetList == null) {if(wordDetManager == null) {

wordDetManager= newWordDetManager();

}

List tmexamWordList =getExamWordList();

Global.examWordDetList=wordDetManager.findMoreWordDet(tmexamWordList);

}

}

b> 获得测试单词范围

private ListgetExamWordList() {//确定单元及组String unitGroupIntro=Global.todayStudyUnitGroupIntroList.get(Global.studyPlanObj.lastUnitGroupIndex);int cunit = Integer.parseInt(unitGroupIntro.split("-")[0]);int cgroup = Integer.parseInt(unitGroupIntro.split("-")[1]);int scopeBegin = -1;int scopeEnd = -1;//确定范围

if(cunit == 1 && cgroup <= 3) {

scopeBegin= (cunit - 1) * ReciteConstant.DUNIT_WORD_COUNT + (cgroup+1) *ReciteConstant.DUNITG_WORD_COUNT;

scopeEnd= scopeBegin + 3 *ReciteConstant.DUNITG_WORD_COUNT;

}else{

scopeEnd= (cunit - 1) * ReciteConstant.DUNIT_WORD_COUNT + cgroup *ReciteConstant.DUNITG_WORD_COUNT;if(scopeEnd >Global.studyPlanObj.allWordCount) {

scopeEnd= Global.studyPlanObj.allWordCount -ReciteConstant.DUNITG_WORD_COUNT;

}

scopeBegin= scopeEnd - 3 *ReciteConstant.DUNITG_WORD_COUNT;

}if(wordDao == null) {

wordDao= newWordDao();

}

String pathStr= PathConstant.STUPLAN_PATH + "sp_" +Global.studyPlanObj.name;returnwordDao.findScope(scopeBegin, scopeEnd, pathStr);

}

c> 根据单词列表得到单词详解列表

这里引用单词详解模块WordDetManager的查找更多单词详解方法

请查看源码点到该类

public List findMoreWordDet(ListwordList) {

List wordDetList = new ArrayList();for(Word word : wordList) {

WordDet wordDet=findDetWord(word.wordStr);if(wordDet != null) {

wordDetList.add(wordDet);

}

}returnwordDetList;

}

查找某个单词的单词详解方法

publicWordDet findDetWord(String wordStr) {if(dictDao == null) {

dictDao= newDictDao();

}

String wordDefinition=dictDao.findWordDefinition(wordStr);

WordDet wordDet=jsonDefiToDefWord(wordStr, wordDefinition);returnwordDet;

}

2>背诵管理更新次数详解

更新背诵次数,直接调用相应的dao即可

public voidupdateReciteProgress(String reciteProgressStr) {if(reciteDao == null) {

reciteDao= newReciteDao ();

}

String pathStr= PathConstant.STUPLAN_PATH + "sp_" +Global.studyPlanObj.name;

reciteDao.updateReciteProgress(reciteProgressStr, Global.studyPlanObj.name, pathStr);

}

到此《android项目实战-背呗单词》重点功能及技术介绍完结

更多请自行下载源码解读

应用下载:请点击

源码下载:请点击

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值