当前位置: 移动技术网 > IT编程>移动开发>Android > Android实现有道辞典查询功能实例详解

Android实现有道辞典查询功能实例详解

2019年07月24日  | 移动技术网IT编程  | 我要评论

鸡精和味精,原平市政府,猎杀电视剧全集下载

本文实例讲述了android实现有道辞典查询功能的方法。分享给大家供大家参考,具体如下:

这是我做的一个简单的有道android的demo,只是简单的雏形。界面设计也有点丑陋呵呵~ 看看下面的效果图:

第一步:思路解析

从界面看一共用了三个控件edittext,button,webview。其实是四个,是当我们查询内容为空的时候用来提示的toast控件。

我们在edittext输入查询内容,这里包括中文,英文。然后通过参数的形式,从取出数据把结果
存放在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;
 //加载数据的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开发入门与进阶教程》、《android视图view技巧总结》、《android编程之activity操作技巧总结》、《android操作sqlite数据库技巧总结》、《android操作json格式数据技巧总结》、《android数据库操作技巧总结》、《android文件操作技巧汇总》、《android编程开发之sd卡操作方法汇总》、《android资源操作技巧汇总》及《android控件用法总结

希望本文所述对大家android程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网