本文实例讲述了Android实现有道辞典查询功能的方法。分享给大家供大家参考,具体如下:
这是我做的一个简单的有道Android的DEMO,只是简单的雏形。界面设计也有点丑陋呵呵~ 看看下面的效果图:
第一步:思路解析
从界面看一共用了三个控件EditText,Button,WebView。其实是四个,是当我们查询内容为空的时候用来提示的Toast控件。
我们在EditText输入查询内容,这里包括中文,英文。然后通过参数的形式,从http://dict.youdao.com/m取出数据把结果
存放在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程序设计有所帮助。
本文向大家介绍Android实现发送短信功能实例详解,包括了Android实现发送短信功能实例详解的使用技巧和注意事项,需要的朋友参考一下 本文实例分析了Android实现发送短信功能的方法。分享给大家供大家参考,具体如下: 短信和打电话一样,都是android手机的基本功能,下面以实例说明android如何实现发送短信的功能。 程序如下所示: AndroidManifest.xml如下: 收到P
本文向大家介绍Python基于有道实现英汉字典功能,包括了Python基于有道实现英汉字典功能的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了Python基于有道实现英汉字典功能的方法。分享给大家供大家参考。具体如下: 希望本文所述对大家的Python程序设计有所帮助。
本文向大家介绍php 实现Hash表功能实例详解,包括了php 实现Hash表功能实例详解的使用技巧和注意事项,需要的朋友参考一下 php 实现Hash表功能 Hash表作为最重要的数据结构之一,也叫做散列表。使用PHP实现Hash表的功能。PHP可以模拟实现Hash表的增删改查。通过对key的映射到数组中的一个位置来访问。映射函数叫做Hash函数,存放记录的数组称为Hash表。 Hash函数把任
本文向大家介绍android实现查询公交车还有几站的功能,包括了android实现查询公交车还有几站的功能的使用技巧和注意事项,需要的朋友参考一下 上一篇文章介绍了如何在Android平台上利用百度地图进行定位,接下来就介绍一下在获取的定位功能的基础上采用百度地图来获取周边的公交信息。 这里采用如上文同样的方式,单独写一个类,该类是对周边搜索功能的封装,NearbySearchHelper。该类
本文向大家介绍layUI实现列表查询功能,包括了layUI实现列表查询功能的使用技巧和注意事项,需要的朋友参考一下 layUI可以直接使用本地的json文件进行列表数据渲染,但,我们会发现,官网ctr+c ctr+v 过来的代码在做查询时每次看起来都有列表刷新的动作,但实际操作无效,百度了一大圈也没找到具体的原因,无奈继续回去看官网,后面总结出只有一点,也是大家比较容易忽略的一点: 官网说在查询时
本文向大家介绍Vue.js实现分页查询功能,包括了Vue.js实现分页查询功能的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了Vue.js实现分页查询的具体代码,供大家参考,具体内容如下 vue.js的使用如下: 1、引入vue.js a、分页条 b、分页条js、css 2、分页的方法 3、封装page方法 4、定义获取总页数的方法 5、前台分页方法,获取后台的数据,实