Hello everyone, this is a simple Android demo, just a simple prototype. The interface design is also a little ugly ~ Take a look at the following:
Step 1: Train of Thought Analysis
Three Controls, edittext, button, and webview, are used from the interface. There are actually four toast controls that are used to prompt when the query content is empty.
We enter the query content in edittext, which includes Chinese and English. Then, obtain the data output from http://dict.youdao.com/mthrough parameters.
Stored in webview.
As shown in:
Step 2: start the program.
First, the layout Interface main. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Absolutelayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<! -- Create an edittext -->
<Edittext
Android: Id = "@ + ID/myedittext1"
Android: layout_width = "200px"
Android: layout_height = "40px"
Android: textsize = "18sp"
Android: layout_x = "5px"
Android: layout_y = "32px"
/>
<! -- Create a button -->
<Button
Android: Id = "@ + ID/mybutton01"
Android: layout_width = "60px"
Android: layout_height = "40px"
Android: text = "query"
Android: layout_x = "205px"
Android: layout_y = "35px"
/>
<Button
Android: Id = "@ + ID/mybutton02"
Android: layout_height = "40px"
Android: layout_width = "50px"
Android: text = "clear"
Android: layout_y = "35px"
Android: layout_x = "270px"
/>
<! -- Create a webview -->
<Webview
Android: Id = "@ + ID/mywebview1"
Android: layout_height = "330px"
Android: layout_width = "300px"
Android: layout_x = "7px"
Android: layout_y = "90px"
Android: Background = "@ drawable/Black"
Android: focusable = "false"
/>
</Absolutelayout>
The second is the main class youdao. Java
Package androidapplication. instance;
Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. WebKit. webview;
Import Android. widget. Button;
Import Android. widget. edittext;
Import Android. widget. Toast;
Public class youdao extends Activity
{
// Query button Declaration
Private button mybutton01;
// Clear button Declaration
Private button mybutton02;
// Input a statement
Private edittext medittext1;
// Webview statement for loading data
Private webview mwebview1;
Public void oncreate (bundle savedinstancestate)
{
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
// Obtain the layout 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 to add events
Mybutton01.setonclicklistener (New button. onclicklistener ()
{
Public void onclick (view arg0)
{
String struri = (medittext1.gettext (). tostring ());
Struri = struri. Trim ();
// Prompt if the query content is empty
If (struri. Length () = 0)
{
Toast. maketext (youdao. This, "the query content cannot be blank! ", Toast. length_long)
. Show ();
}
// Otherwise, the data is retrieved from http://dict.youdao.com/mand redirected to webview.
Else
{
String strurl = "http://dict.youdao.com/m/search? Keyfrom = dict. mindex & Q ="
+ Struri;
Mwebview1.loadurl (strurl );
}
}
});
// Clear the button to add events and leave edittext empty
Mybutton02.setonclicklistener (New button. onclicklistener ()
{
Public void onclick (view V)
{
Medittext1.settext ("");
}
});
}
}
Program success. In fact, you will find that this application is quite simple, but you didn't think of it, narcissism ~. If the program cannot run
You can ask me by email and leave your Q or email in the message.
So far today! Thank you ~