The 300 Songs of Song Ci (ii.) of Android application

Source: Internet
Author: User

On the back, last we talked about mainactivity all the song lyrics and the author display to the interface of the ListView, our next job is to click on the ListView item to jump to contentactivity inside to display all the content of a single song word , jump codes such as the following:

Set the click Listener Mlistview.setonitemclicklistener (New Onitemclicklistener () {@Overridepublic void for the ListView item Onitemclick (adapterview<?> parent, View view,int position, long ID) {// Assigns a reference to the poem object represented by the currently clicked item to CURRENTSONGCIGLOBAL.CURRENTSONGCI = Sclist.get (position);//interface Jump Intent Intent = new Intent ( Mainactivity.this,contentactivity.class); startactivity (intent);});

Here, I use a static variable to record the song word represented by the clicked ListView Item, and then jump to contentactivity.


We're here to first look at the contents of the Contentactivity layout file Activity_content.xml:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:id=" @id/ll_parent "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "and roid:background= "@drawable/bg4" android:orientation= "vertical" > <relativelayout android:layout_width= "             Fill_parent "android:layout_height=" 46.0dip "android:background=" @drawable/toolbar "> <textview Android:id= "@id/tv_app_title" android:layout_width= "Wrap_content" android:layout_height=            "Wrap_content" android:layout_centerhorizontal= "true" android:layout_centervertical= "true" android:text= "@string/app_name" android:textappearance= "Android:textappearancelarge" Android:text            Color= "#ffffffff"/> <button android:id= "@id/btn_back" android:layout_width= "72.0dip" Android:layout_height= "46.0dip "android:layout_alignparentleft=" true "Android:layout_centervertical=" true "Android            : background= "@drawable/btn_left" android:paddingleft= "6.0dip" android:text= "@string/back" Android:textcolor= "#ffffffff" android:textsize= "14.0sp"/> <imageview android:id= "@id/ Iv_font_small "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "a Ndroid:layout_alignparentright= "true" android:layout_centervertical= "true" android:src= "@drawable/fo Nt_small "/> <imageview android:id=" @id/iv_font_big "android:layout_width=" wrap_content "Android:layout_height=" Wrap_content "android:layout_centervertical=" true "android:layou t_toleftof= "@id/iv_font_small" android:src= "@drawable/font_big"/> </RelativeLayout> <scrollv Iew android:id= "@Id/scrollview1 "android:layout_width=" fill_parent "android:layout_height=" 0.0dip "Android:layout_marg             In= "8.0dip" android:layout_weight= "1.0" android:background= "@drawable/item_bg2" > <linearlayout Android:id= "@id/linearlayout1" android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" android:orientation= "vertical" > <textview android:id= "@id/tv_tit Le "style=" @style/black_normal "android:layout_width=" Fill_parent "Android:la yout_height= "Wrap_content" android:layout_margin= "5.0dip" android:text= "title" A Ndroid:textappearance= "? Android:textappearancemedium"/> <linearlayout Android:layout_widt                H= "Fill_parent" android:layout_height= "1.0px" android:layout_marginleft= "5.0dip" Android:layout_marginright= "5.0dip" android:background= "#ff666666"/> <textview android:id= "@id /tv_author "style=" @style/black_normal "android:layout_width=" Fill_parent "an                droid:layout_height= "Wrap_content" android:layout_margin= "5.0dip" android:text= "Author" Android:textappearance= "? Android:textappearancesmall"/> <linearlayout android:layo                Ut_width= "Fill_parent" android:layout_height= "1.0px" android:layout_marginleft= "5.0dip"                 android:layout_marginright= "5.0dip" android:background= "#ff666666"/> <textview Android:id= "@id/tv_desc" style= "@style/black_normal" android:layout_width= "f                Ill_parent "android:layout_height=" fill_parent "android:layout_margin=" 5.0dip " Android:linespacingmulTiplier= "1.3" android:text= "annotations" android:textappearance= "? Android:textappearancesmall"/> </LinearLayout> </ScrollView></LinearLayout>
here, we can find that a song Ci title, author, content, respectively, the corresponding three TextView control.

Then let's look at the contents of contentactivity:

Package Com.example.songcidemo.ui;import Android.app.activity;import Android.content.intent;import Android.os.bundle;import Android.text.html;import Android.text.spanned;import Android.util.Log;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.window;import Android.widget.button;import Android.widget.imageview;import Android.widget.textview;import Com.example.songcidemo.r;import Com.example.songcidemo.bean.songci;import Com.example.songcidemo.util.Global; public class Contentactivity extends Activity {private songci sc;//font becomes smaller buttonprivate ImageView fontsmallimageview;// Font size buttonprivate ImageView fontbigimageview;//representative TextView and body TextView text text sizes default value private float defaulttextsize;// Represents the text text size of the current caption TextView private float currenttitletextsize;//represents the text text size of the current author TextView and the body TextView private float currenttextsize;//representative Title Textviewprivate TextView titletextview;//Representative Textviewprivate TextView authtextview;// Represents the main content textviewprivate TextView desctextview;//representative returns to Buttonprivate BuTton backbtn; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (Window.feature_no_title); Setcontentview (r.layout.activity_content); SetupViews ();} /** * Initialize interface */private void Setupviews () {//through the Findviewbyid () method gets three TextView controls Titletextview = (TextView) Findviewbyid ( R.id.tv_title) Authtextview = (TextView) Findviewbyid (r.id.tv_author);d Esctextview = (TextView) Findviewbyid (r.id.tv _DESC);//assigns CURRENTSONGCI to class variable SCSC = global.currentsongci;//Gets the value of title, author, content by the Get () method String title = Sc.gettitle (); String auth = Sc.getauth (); String desc = Sc.getdesc ();//The content of Song Ci is displayed to three TextView control Titletextview.settext (title); Authtextview.settext (auth);// Html formatting of the string spanned sp = html.fromhtml (desc);d Esctextview.settext (SP);//descwebview.loaddatawithbaseurl ("fake:// Not/needed ", desc," text/html ",//" Utf-8 "," "); LOG.V ("Contentactivity", "" "+ titletextview.gettextsize ()); LOG.V ("Contentactivity", "" "+ authtextview.gettextsize ()); LOG.V ("Contentactivity", "" "+ DesctextView.gettextsize ());//Initialize font size variable defaulttextsize = 14;currenttitletextsize = 20;currenttextsize = 14;fontbigimageview = (ImageView) Findviewbyid (r.id.iv_font_big); Fontsmallimageview = (ImageView) Findviewbyid (R.id.iv_font_small); Set Listener Fontbigimageview.setonclicklistener for Fontbigimageview (new Onclicklistener () {@Overridepublic void OnClick ( View v) {currenttitletextsize++;currenttextsize++;if ((currenttextsize-defaulttextsize) > 5) { currenttitletextsize--;currenttextsize--;} Else{setfont ();}}); /Set Listener Fontsmallimageview.setonclicklistener for Fontsmallimageview (new Onclicklistener () {@Overridepublic void OnClick (View v) {currenttitletextsize--;currenttextsize--;if (defaulttextsize-currenttextsize) > 5) {currenttitletextsize++; currenttextsize++;} Else{setfont ();}}); BACKBTN = (Button) Findviewbyid (r.id.btn_back);//Set Listener Backbtn.setonclicklistener for BACKBTN (new Onclicklistener () {@ overridepublic void OnClick (View v) {//Return to main interface Intent intent = new Intent (contentactivity.this, mainactivity.class); STARtactivity (intent);}});} /** * Set interface font size */private void SetFont () {titletextview.settextsize (currenttitletextsize); Authtextview.settextsize ( currenttextsize);d esctextview.settextsize (currenttextsize);}}

In order to reflect the HTML elements such as <p><br> in Desc, there is a need for a little bit of conversion, which is the sentence
spanned sp = html.fromhtml (DESC);

This activity also implements a function that can change the size of the interface text.

The interface is as follows:



Finally, we will implement a main interface of the search function, my mind is this definition of a arraylist<songci> resultlist this list, because there is already sclist stored in all the song words, with A For loop traversal sclist, Add the results that meet the search criteria to resultlist, and after the search is complete, the ListView displays the contents of the Resultlist, key codes such as the following:

Set the click Listener Searchdialogbtn.setonclicklistener for SEARCHDIALOGBTN (new Onclicklistener () {@Overridepublic void OnClick ( View v) {switch (Currentsearchradiobuttonid) {case R.ID.RADIO0:SEARCHSONGCI (search_type_title); break;case R.ID.RADIO1:SEARCHSONGCI (Search_type_author); Break;case r.id.radio2:searchsongci (SEARCH_TYPE_CONTENT);d efault: break;} Disappears the Search dialog box if (searchdialog.isshowing ()) {Searchdialog.dismiss ();} Initialize result list Adapter Resultsongciadapterif (Resultsongciadapter = = null) {Resultsongciadapter = new Mainlistviewadapter ( Mainactivity.this, resultlist);} ELSE{//notifies the adapter that the source data has changed resultsongciadapter.notifydatasetchanged ();} Mlistview.setadapter (Resultsongciadapter);}});

The content of your own definition method is:

/** * Search for song word results by passing the number of references *  * @param searchtype Search by which criteria (title, CI, content) */private void searchsongci (int searchtype) {// Initialize Resultlistif (resultlist = = null) {resultlist = new arraylist<songci> ();} Else{resultlist.clear ();} Gets the search keyword string searchwords = Searchedittext.gettext (). toString (). Trim (); if (searchwords = = NULL | | searchwords.equals ("")) {return;} for (SONGCI sc:sclist) {switch (searchtype) {case search_type_title:string title = Sc.gettitle ();//Assuming the title includes a keyword, the current song-word object Added to the result list if (Title.contains (searchwords)) {Resultlist.add (SC);} Break;case search_type_author:string auth = Sc.getauth ();//Assuming that the author name includes a keyword, the current song Word object is added to the result list if (Auth.contains ( Searchwords)) {Resultlist.add (SC);} Break;case search_type_content:string desc = Sc.getdesc ();//If the content includes keywords, the current Song Ci object is added to the result list if (Desc.contains ( Searchwords)) {Resultlist.add (SC);} Break;default:break;}}}

The search interface is as follows:



Finally, the source code for the entire project is attached:

The 300 song lyrics of the Android app


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.