English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This article illustrates the method of implementing the YouDao dictionary query function in Android. Shared for everyone's reference, as follows:
This is a simple YouDao Android DEMO I made, just a simple prototype. The interface design is also a bit ugly, hahaha ~ Take a look at the following effect diagram:
First step: thought analysis
From the interface, a total of three controls EditText, Button, WebView are used. In fact, there are four, which is the Toast control used to prompt when the query content is empty.
We enter the query content in EditText, including Chinese and English. Then, in the form of parameters, fromhttp://dict.youdao.com/mExtract the data and get the result
Stored in WebView.
As shown in the figure below:
Second step: start the program
The first step: 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>
Next 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 { //查询按钮声明 private Button myButton01; //清空按钮声明 private Button myButton02; //输入框声明 private EditText mEditText1; //加载数据的WebView声明 private WebView mWebView1; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //获得布局的几个控件 myButton01 = (Button) findViewById(R.id.myButton01); myButton02 = (Button) findViewById(R.id.myButton02); mEditText1 = (EditText) findViewById(R.id.myEditText1); mWebView1 = (WebView) findViewById(R.id.myWebView1); //查询按钮添加事件 myButton01.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { String strURI = (mEditText1.getText().toString()); strURI = strURI.trim(); //如果查询内容为空提示 if (strURI.length() == 0) { Toast.makeText(YouDao.this, "查询内容不能为空!", Toast.LENGTH_LONG) .show(); } //否则则以参数的形式从http:\/\///dict.youdao.com/m取得数据,加载到WebView里. else { String strURL = "http:\/\/"//dict.youdao.com/m/search?keyfrom=dict.mindex&q=" + strURI; mWebView1.loadUrl(strURL); } } }); //Fügen Sie das Ereignis zum Leeren des Buttons hinzu und leeren Sie den EditText myButton02.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { mEditText1.setText(""); } }); } }
Das Programm ist großartig gelungen. Tatsächlich wird man feststellen, dass diese Anwendung ziemlich einfach ist, nur dass man es nicht erwartet hat, Narcissism mal呵呵~.
Interessierte Leser, die mehr über Android-Themen erfahren möchten, können die Themenbereiche dieser Website besuchen: "Android-Entwicklung für Anfänger und Fortgeschrittene", "Android-View-View-Tipps zusammengefasst", "Aktivity-Operationstipps für Android zusammengefasst", "SQLite-Datenbankoperationstipps für Android zusammengefasst", "json-Format-Datenoperationstipps für Android zusammengefasst", "Datenbankoperationstipps für Android zusammengefasst", "Dateioperationstipps für Android zusammengefasst", "SD-Karte-Operationstipps für Android zusammengefasst", "Ressourcennutzungstipps für Android zusammengefasst" und "Kontrollen-Nutzungszusammenfassung für Android".
Hoffentlich hilft Ihnen der in diesem Artikel beschriebene Inhalt bei der Android-Programmgestaltung.
Erklärung: Der Inhalt dieses Artikels wurde aus dem Internet übernommen und gehört dem jeweiligen Urheberrechtsinhaber. Der Inhalt wurde von Internetbenutzern selbstständig beigesteuert und hochgeladen. Diese Website besitzt keine Eigentumsrechte und hat den Inhalt nicht von Hand bearbeitet. Sie übernimmt keine Haftung für rechtliche Fragen. Wenn Sie verdächtige urheberrechtliche Inhalte finden, sind Sie herzlich eingeladen, eine E-Mail an notice#w zu senden.3codebox.com (Bitte ersetzen Sie # durch @ beim Senden einer E-Mail zur Meldung von Verstößen und fügen Sie relevante Beweise bei. Sobald nachgewiesen, wird diese Website die beanstandeten urheberrechtlichen Inhalte sofort löschen.)