Android Project Combat-recite the word dev06-word reciting realization

Source: Internet
Author: User

This article explains

This article we carry on the word recitation realization explanation

The word recitation function is mainly worddetactivity in the word explanation interface.

> Click the button in the word list interface to go to the word-detailed interface to do a unit-group-wide vocabulary learning

> in the word detail interface only the unit group range of Word Learning records, to be tested after the study once.

Otherwise, it is not logged to the database

Effect

Flow chart

Detailed description of the Word interface function flow

1> Show Word Details

The Worddetview.getviev (Activity, Worddet) method is used here.

Most of the interface composition is implemented by the code, the word detailed view interface will be detailed

Private voidLoadview () {Worddet= Global.wordDetList.get (global.studyedwordid-1); //Banner title Display wordHftitletextview.settext (WORDDET.WORDSTR); //Show ViewView Reciteview= Worddetview.getview ( This, Worddet); Linearlayout.layoutparams LP=Newlinearlayout.layoutparams (LinearLayout.LayoutParams.MATCH_PARENT, Linearlayout.layoutpar Ams.      Match_parent);      RECITEVIEW.SETLAYOUTPARAMS (LP); Reciteview.setpadding (8, 0, 8, 0); Worddetlinearlayout.addview (Reciteview);}

2> switch to the next word

a> Add next Word button click Listen

Private voidlogic () {Nextbutton.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (view view) {if(Global.studyedwordid! =Global.wordDetList.size ()) {Global.studyedwordid+ = 1;            Tonextword (); } Else{toast.maketext (context,"The current unit has been learned once, into the test", Toast.length_long). Show (); Global.studyedwordid= 1; Tonextview (wordexamactivity.class); }         }      });}

b> switch to the next word

Private void Tonextword () {      worddetlinearlayout.removeallviews ();      Loadview ();}

Detailed description of the Word view class Worddetview

This class mainly generates most of the interface controls

1> get a detailed word View

 Public StaticView GetView (activity tmpactivity, Worddet Tmpworddet) {activity=tmpactivity; Worddet=Tmpworddet; //determine the layoutconfirmlayout (); //Add a Word string viewAddwordstrtextview (); //Add phonetic string ViewAddprontextview (); //add interpretation-related views (including title and content)Adddefview (); //add a related view of the example (including title and content)Addexamplesview (); returnScrollView;}

2> determine the layout

 Private Static voidconfirmlayout () {//First step: Create a scrolling viewScrollView=NewScrollView (activity); //Step Two: Create a linear layout and join in the scrolling viewLinearLayout=Newlinearlayout (activity);        Linearlayout.setorientation (linearlayout.vertical); Scrollview.layoutparams LP=Newscrollview.layoutparams (LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATC H_parent);
Lp.setmargins (0, 0, 0, 0); Lp.gravity=Gravity.fill_horizontal; LINEARLAYOUT.SETLAYOUTPARAMS (LP); Scrollview.addview (LinearLayout);}

3> Add a Word string view

Private Static void Addwordstrtextview () {      new  TextView (activity);        Wordstrtextview.settext (WORDDET.WORDSTR);        Wordstrtextview.settextsize (+);        Wordstrtextview.settypeface (null, typeface.normal);        Wordstrtextview.settextcolor (0xff000088);        Linearlayout.addview (Wordstrtextview);}

4> Add phonetic string View

Private Static void Addprontextview () {      new  TextView (activity);      Pronview.settext (String.Format ("/%s/", Worddet.pron));      Pronview.settextsize ();      Pronview.settextcolor (0xff000000);      Linearlayout.addview (Pronview);}

5> Add interpretation related views ( including title and content )

Private Static voidAdddefview () {//1th Step: Get the Interpretation content collectionList<String> deflist =worddet.definitions; //2nd Step: Add an Interpretation title        if(Deflist! =NULL&& deflist.size () > 0) {TextView Defindicatorview=NewTextView (activity); Defindicatorview.settext (Interpretation); Defindicatorview.settextsize (14); Defindicatorview.settextcolor (0xff000000);            Defindicatorview.setbackgroundcolor (Activity.getresources (). GetColor (R.COLOR.VRED2)); Linearlayout.layoutparams Lpindic=Newlinearlayout.layoutparams (LinearLayout.LayoutParams.MATCH_PARENT, LINEARLAYOUT.LAYOUTP Arams.            Wrap_content); Lpindic.setmargins (0, 8, 0, 8);            Defindicatorview.setlayoutparams (Lpindic);                   Linearlayout.addview (Defindicatorview); }        //3rd Step: Add Interpretation content (contains multiple)        if(Deflist! =NULL&& deflist.size () > 0) {             for(String defitext:deflist) {TextView Origview=NewTextView (activity);                Origview.settext (Defitext); Origview.settextsize (16); Origview.settextcolor (0xff000000);                                   Linearlayout.addview (Origview); }               }      }

6> Add a related view of an example ( including title and content )

Private Static voidAddexamplesview () {//1th step: Get English and Chinese for example setList<String> examplesoriglist =Worddet.examplesorig; List<String> examplestranslist =Worddet.examplestrans; //2nd Step: Add for example title      if(Examplesoriglist! =NULL&& examplesoriglist.size ()! = 0) {TextView Examplesview=NewTextView (activity); Examplesview.settext (Examples); Examplesview.settextsize (14); Examplesview.settextcolor (0xff000000); Examplesview.setbackgroundcolor (Activity.getresources (). GetColor (R.COLOR.VRED2));
Linearlayout.layoutparams Lpindic=Newlinearlayout.layoutparams (LinearLayout.LayoutParams.MATCH_PARENT, LINEARLAYOUT.LAYOUTP Arams. Wrap_content); Lpindic.setmargins (0, 16, 0, 8); Examplesview.setlayoutparams (Lpindic); Linearlayout.addview (Examplesview); } //3rd Step: Add English and Chinese sentences for(inti = 0; I < examplesoriglist.size (); ++i) {//English sentencesTextView Origview=NewTextView (activity); Origview.settext (Examplesoriglist.get (i). Replace ("<em>", "" "). Replace (" </em> "," ")); Origview.settextsize (16); Origview.settextcolor (0xff000000); Linearlayout.addview (Origview); //Chinese TranslationTextView Transview=NewTextView (activity); Transview.settext (Examplestranslist.get (i)); Transview.settextsize (16);
Linearlayout.layoutparams Lptrans=Newlinearlayout.layoutparams (LinearLayout.LayoutParams.WRAP_CONTENT, line ArLayout.LayoutParams.WRAP_CONTENT); Lptrans.setmargins (0, 0, 0, 0); Transview.setlayoutparams (Lptrans); Transview.settextcolor (0xff888888); Linearlayout.addview (Transview); }}

More please download the Source code interpretation

Application Download: please click

Source Download: please click

Android Project Combat-recite the word dev06-word reciting realization

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.