Simple implementation of Android youdao dictionary

Source: Internet
Author: User

The program interface is as follows!

1. layout file:

Copy codeThe Code is as follows: <AbsoluteLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: orientation = "vertical">

<EditText
Android: id = "@ + id/editText"
Android: layout_width = "150px"
Android: layout_height = "40px"
Android: layout_x = "5px"
Android: layout_y = "32px"
Android: textSize = "18sp"/>

<Button
Android: id = "@ + id/btnsearch"
Android: layout_width = "60px"
Android: layout_height = "40px"
Android: layout_x = "165px"
Android: layout_y = "35px"
Android: text = "query"/>

<Button
Android: id = "@ + id/btnclear"
Android: layout_width = "60px"
Android: layout_height = "40px"
Android: layout_x = "230px"
Android: layout_y = "35px"
Android: text = "clear"/>

<WebView
Android: id = "@ + id/reswebView"
Android: layout_width = "300px"
Android: layout_height = "330px"
Android: layout_x = "7px"
Android: layout_y = "90px"
Android: focusable = "false"/>

</AbsoluteLayout>

2. Modify MainActivity:
Copy codeThe Code is as follows: public class MainActivity extends Activity {
Private Button btnSearch;
Private Button btnClear;
Private EditText editText;
Private WebView reswebView;

Private void SetView (){
BtnSearch = (Button) findViewById (R. id. btnsearch );
BtnClear = (Button) findViewById (R. id. btnclear );
EditText = (EditText) findViewById (R. id. editText );
ReswebView = (WebView) findViewById (R. id. reswebView );
BtnSearch. setOnClickListener (new OnClickListener (){
@ Override
Public void onClick (View v ){
String strUri = editText. getText (). toString ();
StrUri = strUri. trim ();
If (strUri. length () = 0 ){
Toast. makeText (getApplicationContext (), "Enter the query character", 1). show ();
} Else {
String strURL = "http://dict.youdao.com/m/search? Keyfrom = dict. mindex & q = "+ strUri;
ReswebView. loadUrl (strURL );
}
}
});
BtnClear. setOnClickListener (new OnClickListener (){
@ Override
Public void onClick (View v ){
EditText. setText ("");
}
});
}

@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
SetView ();
}
}

3. Add the network access permission to the configuration file:

<Uses-permission android: name = "android. permission. INTERNET"/>

Run the program!

Related Article

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.