Android Project Combat-recite word dev07-word test implementation

Source: Internet
Author: User

This article explains

This article we carry on the word test realization explanation

This is the word test interface wordexamactivity function

Layouts also need to be implemented in XML

But you also need to have a word test view class to set some values to see the control source.

In this interface, the data is updated after the test is finished

Effect

Flow chart

Word Test interface function flow detailed

1> Display word test information

A> first to load the word test data

Need to invoke Word test Management module to load data function

 private  void   Loadwordexamdata () {loadingexamdataprogressbar  = (ProgressBar) Findviewbyid (R.id.loadingexamdataprogressbar);      Loadingexamdataprogressbar.setvisibility (view.visible);  new   Thread () { public  void   run () { new   Wordexammanager (). LoadData ();                SYSTEMUTIL.SLEEPVD ( 2000);            Myhandler.sendemptymessage ( 0);   }}.start (); }

B> handler processing 0 of messages and initiating and processing logic

@SuppressLint ("Handlerleak")   Private voidInithandler () {MyHandler=NewHandler () { Public voidhandlemessage (android.os.Message msg) {Switch(msg.what) { Case0: Wordexamlinearlayout.setvisibility (view.visible);                   Loadingexamdataprogressbar.setvisibility (View.gone);                   Init ();                   Logic ();  Break;   }         }      }; }

C> then load the display Word test interface in the initial

Private void Loadview () {      /// correct option random number        = Math.floor (Math.random () * 4 + 1)      ; = Global.wordDetList.get (global.studyedwordid-1);       // Word test title        + string.format ("/%s/", Worddet.pron));      Wordexamview.initoptions (this);      Wordexamview.setoptionsdata (Worddet);}

2> four options to add a listener

To make the click to determine the correct or error selection. Further determining the implementation

Monitoring class Please check the source code yourself

Private void logic () {      for (int i=1; i<=4; i++) {         = WordExamView.weOptionLLayoutList.get (i-1);         Wordexamoptionll.setonclicklistener (new  Wordexamoptionclicklistener (WORDEXAMOPTIONLL, i));}      } 

3> test right after the next

A> Jump Next

Automatically jumps to the next one when the radio is selected correctly

If this is the last one, then update the data

 public  void        Examnext () {global.studyedwordid  + = 1 if  (global.studyedwordid <= Global.wordList.size ()) {Timer.schedule ( new   TimerTask () {@Override  public  void   run () {myhandler.sendemptymessage ( 1);      }},  1000);  else  if  ((global.studyedwordid      > Global.wordList.size ())) {UpdateData (); }}

B> use Timer control to jump after 1 seconds

Handler asynchronous task processing 1 message test the next word

@SuppressLint ("Handlerleak")   Private voidInithandler () {MyHandler=NewHandler () { Public voidhandlemessage (android.os.Message msg) {Switch(msg.what) { Case1:                   if(Timer! =NULL) {timer.cancel (); } Timer=NewTimer ();                   Shownextview ();  Break; }         }      }; }

c> Updating data

If you have finished testing the last one, update the data.

If you jump from the word recitation interface, update the number of records

Private voidUpdateData () {clear (); if(Parentstr! =NULL&& parentstr.equals ("Worddet") {updatedataprogressdialog.setmessage ("Updating Data");              Updatedataprogressdialog.show (); NewThread () {@Override Public voidrun () {updaterecordtimes ();      }}.start (); } Else if(Parentstr.equals ("WordList") {toast.maketext (context, Global.selectunitgroupflagstr+ "unit test group finished, back to the word list interface!!! ", Toast.length_long). Show (); Tonextview (wordlistactivity.class); } }

D> Update times

> No completion progress to set up need to update data

> If the result record count is equal to the number of times you need to recite, return to today's task

Progress is 0 (will be stored in the database), but also need to clear the word record table and the Word table

> returns to the word list, incrementing the progress (not saved to the database)

Private voidUpdaterecordtimes () {
intRecitedtimes =Integer.parseint (Global.studyPlanObj.lastReciteProgressStr.split ("/") [0]); intResultrtimes = 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> actions after testing for errors

Show button action after test error

> Return to the Learning button to return to the word list interface for learning

> Continue the Test button to start the test again

 Public voidshowbuttonafternotright () {returntostudybutton.setvisibility (view.visible);      Continueexambutton.setvisibility (view.visible); Returntostudybutton.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {clear (); Tonextview (wordlistactivity.class);      }      }); Continueexambutton.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {Global.studyedwordid= 1; Global.examedwordid= 1;            Returntostudybutton.setvisibility (View.gone);            Continueexambutton.setvisibility (View.gone);         Shownextview ();  }      }); }

Word Test background function detailed

The data is loaded and the update times method is used in the backend module

The following module functions are used

> Word test Management wordexammanager Load Data LoadData () method

> Recitation Management recitemanager update recitation number updatereciteprogress () method

1> Word test Management load data detailed

A> first is the load data method

 Public void LoadData () {      ifnull)         {ifnull) {             New Worddetmanager ();         }         List<Word> tmexamwordlist = getexamwordlist ();         Global.examworddetlist  = Worddetmanager.findmoreworddet (tmexamwordlist);      }}

B> Get test Word Range

PrivateList<word>getexamwordlist () {//identify units and groupsString Unitgroupintro=Global.todayStudyUnitGroupIntroList.get (Global.studyPlanObj.lastUnitGroupIndex); intCunit = Integer.parseint (Unitgroupintro.split ("-") [0]); intCgroup = Integer.parseint (Unitgroupintro.split ("-") [1]); intScopebegin =-1; intScopeend =-1; //Determine scope      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> list of words by word list

Here refer to the word in detail module Worddetmanager Find more words detailed method

Please check the source point to this class

 Public List<worddet> Findmoreworddet (list<word> wordList) {      Listnew arraylist< Worddet>();        for (Word word:wordlist) {         = Finddetword (word.wordstr);          if NULL ) {            worddetlist.add (worddet);         }      }
return worddetlist;}

Find a word in a word

 Public worddet Finddetword (String wordstr) {      ifnull) {         new  Dictdao ();      }       = dictdao.findworddefinition (wordstr);       = Jsondefitodefword (wordstr, worddefinition);       return Worddet;}

2> Recitation Management Update number of detailed

Update the number of recitation, directly call the appropriate DAO can

 Public void updatereciteprogress (String reciteprogressstr) {      ifnull) {         new  Recitedao ();      }       = Pathconstant.stuplan_path + "sp_" + Global.studyPlanObj.name;      Recitedao.updatereciteprogress (Reciteprogressstr, Global.studyPlanObj.name, pathstr);}

To this "Android project combat-recite words" key features and technical introduction end

More please download the Source code interpretation

Application Download: please click

Source Download: please click

Android Project Combat-recite word dev07-word test implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.