English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This article describes the method of implementing the Youdao Dictionary query function in Android. Share it with everyone for reference, as follows:
This is a simple YouDao Android DEMO I made, just a simple prototype. The interface design is a bit ugly,呵呵~ Take a look at the following effect picture:
First step: Idea analysis
From the interface, it seems that three controls EditText, Button, WebView are used in total. In fact, there are four, which is a Toast control used to prompt when the query content is empty.
We input the query content in EditText, which includes Chinese and English. Then, in the form of parameters, fromhttp://dict.youdao.com/mExtract the data and output the result
Stored in WebView.
As shown in the figure below:
Second step: Start the program
The first step is to establish 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 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" /> <!-- Establish 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" /> <!-- 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>
The main class is 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 { //Declaration of query button private Button myButton01; //Declaration of clear button private Button myButton02; //Declaration of input box private EditText mEditText1; //Declaration of WebView to load data private WebView mWebView1; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Obtain several controls of the layout myButton01 = (Button) findViewById(R.id.myButton01); myButton02 = (Button) findViewById(R.id.myButton02); mEditText1 = (EditText) findViewById(R.id.myEditText1); mWebView1 = (WebView) findViewById(R.id.myWebView1); //Add an event to the query button myButton01.setOnClickListener(new Button.OnClickListener()) { public void onClick(View arg0) { String strURI = (mEditText1.getText().toString()); strURI = strURI.trim(); //If the query content is empty, prompt if (strURI.length() == 0) { Toast.makeText(YouDao.this, "The query content cannot be empty!", Toast.LENGTH_LONG) .show(); } //Otherwise, obtain it in the form of parameters from http:\://dict.youdao.com/m gets data, loads it into WebView. else { String strURL = "http:\"://dict.youdao.com/m/search?keyfrom=dict.mindex&q=" + strURI; mWebView1.loadUrl(strURL); } } }); //Add event to clear button, set EditText to empty myButton02.setOnClickListener(new Button.OnClickListener()) { public void onClick(View v) { mEditText1.setText(""); } }); } }
The program is successfully completed. In fact, you will find that this application is quite simple, just that you didn't think of it, Narcissism, haha~.
Readers who are interested in more content related to Android can check the special topics on this site: 'Android Development入门与进阶教程', 'Android View View Skills Summary', 'Summary of Activity Operation Skills in Android Programming', 'Summary of SQLite Database Operation Skills in Android', 'Summary of JSON Format Data Operation Skills in Android', 'Summary of Database Operation Skills in Android', 'Summary of File Operation Skills in Android', 'Summary of SD Card Operation Methods in Android Programming Development', 'Summary of Resource Operation Skills in Android', and 'Summary of Android Control Usage'
I hope the content described in this article will be helpful to everyone in Android program design.
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)