Android Realization Youdao Thesaurus Query Function example detailed _android

Source: Internet
Author: User
Tags sqlite database

This article is an example of Android to achieve Youdao Dictionary query function method. Share to everyone for your reference, specific as follows:

This is what I do a simple Youdao Android demo, just a simple prototype. The interface design is also a bit ugly oh ~ look at the following effect chart:

The first step: the analysis of Ideas

A total of three control Edittext,button,webview are used from the interface. It's actually four, which is the toast control we use to prompt when our query content is empty.

We enter the inquiry content in EditText, here includes Chinese, English. And then, by the form of the parameter, the data is removed from the http://dict.youdao.com/m
stored in the WebView.

As shown in the following illustration:

Step Two: Start program

First is 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 " > <!--establish a edittext--> <edittext android:id= "@+id/myedittext1" android:layout_width= "200px" Android:layo ut_height= "40px" android:textsize= "18sp" android:layout_x= "5px" android:layout_y= "32px"/> <!--set up a button--&G
 T
 <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_heigh t= "40px" android:layout_width= "50px" android:text= "Empty" android:layout_y= "35px" android:layout_x= "270px"/> &L t;! --Establish 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> 

followed by 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 affirms private button myButton01;
 Empty button to declare private button myButton02;
 The input box declares private edittext mEditText1;
 Load data WebView stated that private WebView mWebView1;
  public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
  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 Mybutton01.setonclicklistener (new Button.onclicklistener () {public void OnClick (View arg0) {S
     Tring Struri = (Medittext1.gettext (). toString ()); Struri = Struri.trim ();
        If the query content is null prompt if (struri.length () = = 0) {toast.maketext (youdao.this, "query content cannot be empty!", Toast.length_long)
     . Show ();
     //Otherwise obtain data from http://dict.youdao.com/m in the form of parameters and load into WebView.
      else {String strURL = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&q=" + Struri;
     Mwebview1.loadurl (strURL);
  }
    }
  });
   The empty button adds an event, edittext the Empty Mybutton02.setonclicklistener (new Button.onclicklistener () {public void OnClick (View v)
   {Medittext1.settext ("");
 }
  });

 }
}

The program is done. In fact, we will find that the application is quite simple, but you did not think of it, narcissism ah ~.

More interested readers of Android-related content can view the site: Android Development Primer and Advanced tutorials, the Android View View tips Summary, the activity tips summary of Android programming, Android Operation SQLite Database skills Summary, "Android operation JSON format Data Skills summary", "Android Database Operation skills Summary", "Android File Operation skills Summary", "Android programming development of SD card operation method Summary", " Android Resource Operation tips Summary and the "Android Controls usage Summary"

I hope this article will help you with the Android 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.