The first step: thinking Analysis
From the interface, altogether three control Edittext,button,webvieware used. is actually four, is the Toast control that is used to prompt when we query the content is empty. We enter the contents of the enquiry in EditText, which includes Chinese and English. The data is then extracted from the http://dict.youdao.com/m in the form of parameters to store the results in the webview. As shown in the following:
Next, create a layout with the following XML code:
1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Android:background= "@drawable/mainbg"6 Android:paddingbottom= "@dimen/activity_vertical_margin"7 Android:paddingleft= "@dimen/activity_horizontal_margin"8 Android:paddingright= "@dimen/activity_horizontal_margin"9 Android:paddingtop= "@dimen/activity_vertical_margin"Ten Tools:context=". Mainactivity " > One A <EditText - Android:id= "@+id/etword" - Android:layout_width= "Wrap_content" the Android:layout_height= "Wrap_content" - Android:layout_alignparentleft= "true" - Android:layout_alignparenttop= "true" - Android:layout_margintop= "27DP" + Android:background= "@android:d rawable/edit_text" - Android:ems= "Ten" + Android:singleline= "true" A Android:textcolor= "#552006" at Android:textcolorhint= "#782f10" > - - <Requestfocus/> - </EditText> - - <Button in Android:id= "@+id/btnsearch" - Android:layout_width= "Wrap_content" to Android:layout_height= "Wrap_content" + Android:layout_alignright= "@+id/tvsearchresult" - Android:layout_aligntop= "@+id/etword" the Android:background= "@drawable/ibsearchword" * Android:onclick= "Search" /> $ Panax Notoginseng <WebView - Android:id= "@+id/wvsearchresult" the Android:layout_width= "Match_parent" + Android:layout_height= "Match_parent" A Android:layout_alignleft= "@+id/etword" the Android:layout_below= "@+id/etword" + Android:layout_margintop= "22DP" - Android:background= "@drawable/bg_roundcorner" $ android:textappearance= "? Android:attr/textappearancemedium" $ android:textsize= "25SP" /> - - </Relativelayout>
Some students may have problems when using the WebView control:
The first of these methods
1 Instantiate the WebView component in an activity: WebView WebView = new WebView (this);
2. Call WebView's Loadurl () method, set Wevview to display the Web page: Internet: Webview.loadurl ("http://www.google.com"); For local files: Webview.loadurl ("file:///android_asset/XX.html"); Local files are stored in the: Assets file
3. Call the activity's Setcontentview( ) method to display the page view
4. Use WebView point link to see a lot of pages later in order to let WebView support fallback function, need to overwrite the Activity class onkeydown () method, if do not do any processing, click the system fallback shear key, the entire browser will call finish () and end itself, Instead of retreating back to the previous page
5. You need to add permissions to the Androidmanifest.xml file, or the Web page not available error will occur. <uses-permission android:name="Android.permission.INTERNET" />
The second method:
1. Declare webview in the layout file
2, in the activity of the instantiation of WebView
3, call WebView Loadurl () method, set Wevview to display the page
4. To enable WebView to respond to hyperlinks, call the Setwebviewclient () method to set the WebView view
5, with WebView point link to see a lot of pages later in order to let WebView support fallback function, need to overwrite the Activity class onkeydown () method, if do not do any processing, click the system fallback shear key, the entire browser will call finish () and end itself, Instead of retreating back to the previous page
6. You need to add permissions to the Androidmanifest.xml file, or the Web page not available error occurs.
<uses-permission android:name= "Android.permission.INTERNET"/>
1 Public classYoudaoextendsActivity2 {3 //Query Button Declaration4 PrivateButton MyButton01;5 //Clear Button Declaration6 PrivateButton myButton02;7 //Input Box Declaration8 PrivateEditText MEditText1;9 //WebView Declaration of loading DataTen PrivateWebView MWebView1; One A Public voidonCreate (Bundle savedinstancestate) - { - Super. OnCreate (savedinstancestate); the Setcontentview (r.layout.main); - //get the layout of several controls -MyButton01 =(Button) Findviewbyid (r.id.mybutton01); -MYBUTTON02 =(Button) Findviewbyid (R.ID.MYBUTTON02); +MEditText1 =(EditText) Findviewbyid (R.ID.MYEDITTEXT1); -MWebView1 =(WebView) Findviewbyid (r.id.mywebview1); + //Query button Add Event AMybutton01.setonclicklistener (NewButton.onclicklistener () at { - Public voidOnClick (View arg0) - { -String Struri =(Medittext1.gettext (). toString ()); -Struri =Struri.trim (); - //If the query content is empty prompt in if(struri.length () = = 0) - { toToast.maketext (Youdao. This, "The contents of the query cannot be empty!", Toast.length_long) + . Show (); - } the //Otherwise, it is in the form of an argument from http://dict.youdao.com/m Gets the data and loads it into the webview. * Else $ {Panax NotoginsengString strURL = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&q=" -+Struri; the Mwebview1.loadurl (strurl); + } A } the }); + //Http://dict.youdao.com/m/search?keyfrom=dict.mindex&q=happy - //empty button to add event, EditText empty $Mybutton02.setonclicklistener (NewButton.onclicklistener () $ { - Public voidOnClick (View v) - { theMedittext1.settext (""); - }Wuyi }); the } -}
Introduction to the simple implementation of the Youdao Dictionary of Android