发布于 2017-09-30 11:24:07 | 146 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章主要介绍了Android实现有道辞典查询功能的方法,结合实例形式较为详细的分析了Android基于有道词典查询功能的原理与具体实现技巧,需要的朋友可以参考下

本文实例讲述了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程序设计有所帮助。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务