Android實現(xiàn)有道辭典查詢功能實例詳解
本文實例講述了Android實現(xiàn)有道辭典查詢功能的方法。分享給大家供大家參考,具體如下:
這是我做的一個簡單的有道Android的DEMO,只是簡單的雛形。界面設(shè)計也有點丑陋呵呵~ 看看下面的效果圖:
第一步:思路解析
從界面看一共用了三個控件EditText,Button,WebView。其實是四個,是當(dāng)我們查詢內(nèi)容為空的時候用來提示的Toast控件。
我們在EditText輸入查詢內(nèi)容,這里包括中文,英文。然后通過參數(shù)的形式,從http://dict.youdao.com/m取出數(shù)據(jù)把結(jié)果
存放在WebView里。
如下圖所示:
第二步:入手程序
首先是布局界面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" > <!-- 建立一個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" /> <!-- 建立一個Button --> <Button android:id="@+id/myButton01" android:layout_width="60px" android:layout_height="40px" android:text="查詢" android:layout_x="205px" android:layout_y="35px" /> <Button android:id="@+id/myButton02" android:layout_height="40px" android:layout_width="50px" android:text="清空" android:layout_y="35px" android:layout_x="270px" /> <!-- 建立一個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>
其次是主類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; //加載數(shù)據(jù)的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(); //如果查詢內(nèi)容為空提示 if (strURI.length() == 0) { Toast.makeText(YouDao.this, "查詢內(nèi)容不能為空!", Toast.LENGTH_LONG) .show(); } //否則則以參數(shù)的形式從http://dict.youdao.com/m取得數(shù)據(jù),加載到WebView里. else { String strURL = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&q=" + strURI; mWebView1.loadUrl(strURL); } } }); //清空按鈕添加事件,將EditText置空 myButton02.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { mEditText1.setText(""); } }); } }
程序大功告成。其實大家會發(fā)現(xiàn),這個應(yīng)用相當(dāng)簡單,只是你們沒有想到而已,Narcissism一下呵呵~。
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android操作SQLite數(shù)據(jù)庫技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
- Android組件WebView編寫有道詞典小案例分享
- Android 有道詞典的簡單實現(xiàn)方法介紹
- Android優(yōu)化查詢加載大數(shù)量的本地相冊圖片
- 淺析Android手機衛(wèi)士之號碼歸屬地查詢
- Android手機號碼歸屬地的查詢
- Android編程實現(xiàn)號碼歸屬地查詢的方法
- Android編程操作聯(lián)系人的方法(查詢,獲取,添加等)
- Android中的SQL查詢語句LIKE綁定參數(shù)問題解決辦法(sqlite數(shù)據(jù)庫)
- Android 軟件自動更新功能實現(xiàn)的方法
- android實現(xiàn)倒計時功能代碼
- Android實現(xiàn)上傳文件功能的方法
相關(guān)文章
viewPager+fragment刷新緩存fragment的方法
這篇文章主要介紹了viewPager+fragment刷新緩存fragment的方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-03-03Android編程實現(xiàn)手機自帶內(nèi)部存儲路徑的獲取方法
這篇文章主要介紹了Android編程實現(xiàn)手機自帶內(nèi)部存儲路徑的獲取方法,涉及Android針對掛載點信息的獲取技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-11-11詳解Android 在 ViewPager 中使用 Fragment 的懶加載
本篇文章主要介紹了Android 在 ViewPager 中使用 Fragment 的懶加載,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06解決android 顯示內(nèi)容被底部導(dǎo)航欄遮擋的問題
今天小編就為大家分享一篇解決android 顯示內(nèi)容被底部導(dǎo)航欄遮擋的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-07-07Android文本輸入框(EditText)輸入密碼時顯示與隱藏
這篇文章主要介紹了Android文本輸入框(EditText)輸入密碼時顯示與隱藏的方法和示例,需要的朋友可以參考下2014-12-12Android自定義View實現(xiàn)自動轉(zhuǎn)圈效果
這篇文章主要為大家詳細介紹了Android自定義View實現(xiàn)自動轉(zhuǎn)圈效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05