国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實現有道辭典查詢功能實例詳解

2019-10-23 20:08:59
字體:
來源:轉載
供稿:網友

本文實例講述了Android實現有道辭典查詢功能的方法。分享給大家供大家參考,具體如下:

這是我做的一個簡單的有道Android的DEMO,只是簡單的雛形。界面設計也有點丑陋呵呵~ 看看下面的效果圖:

Android,有道辭典,查詢功能

第一步:思路解析

從界面看一共用了三個控件EditText,Button,WebView。其實是四個,是當我們查詢內容為空的時候用來提示的Toast控件。

我們在EditText輸入查詢內容,這里包括中文,英文。然后通過參數的形式,從http://dict.youdao.com/m取出數據把結果
存放在WebView里。

如下圖所示:

Android,有道辭典,查詢功能

第二步:入手程序

首先是布局界面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; //加載數據的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);     }    }  });  //清空按鈕添加事件,將EditText置空  myButton02.setOnClickListener(new Button.OnClickListener()  {   public void onClick(View v)   {    mEditText1.setText("");   }  }); }}

程序大功告成。其實大家會發現,這個應用相當簡單,只是你們沒有想到而已,Narcissism一下呵呵~。

希望本文所述對大家Android程序設計有所幫助。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嘉善县| 中山市| 唐海县| 双峰县| 汨罗市| 房产| 邵阳县| 祥云县| 武宣县| 商南县| 博乐市| 伽师县| 通渭县| 黄平县| 曲阜市| 扎兰屯市| 秦皇岛市| 贺兰县| 日照市| 镇雄县| 富裕县| 中方县| 宁南县| 家居| 汽车| 张掖市| 大余县| 阿坝县| 望奎县| 涿州市| 崇信县| 胶州市| 门头沟区| 盐池县| 清丰县| 泽普县| 南溪县| 荔波县| 周口市| 扎赉特旗| 扎赉特旗|