android中的有道词典实例
16lz
2021-12-04
1、布局文件main.xml
主程序
<?xml version="1.0" encoding="utf-8"?>
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:id="@+id/editTextid"
android:layout_width="200px"
android:layout_height="wrap_content"
android:layout_x="5px"
android:layout_y="32px"
/>
主程序
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class YoudaoActivity extends Activity {
/** Called when the activity is first created. */
private EditText editString;
private Button query;
private Button clear;
private WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
query = (Button)findViewById(R.id.query);
clear = (Button)findViewById(R.id.clear);
query.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
editString = (EditText)findViewById(R.id.editTextid);
String strURL = editString.getText().toString();
strURL = strURL.trim();
webview = (WebView)findViewById(R.id.webViewId);
if (strURL.length() == 0) {
Toast.makeText(YoudaoActivity.this, "查询内容不能为空!", Toast.LENGTH_LONG).show();
}
else
{
String url = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&q="+strURL;
webview.loadUrl(url);
}
}
});
clear.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
editString.setText("");
}
});
}
}
更多相关文章
- Android(安卓)3.1 r1 中文API文档 (120) —— SearchView
- android中的有道词典实例
- android 注册、登录实现程序
- android 注册、登录实现程序
- Android(安卓)Contacts的使用(一)
- android 逐帧动画
- 设置Android(安卓)app背景图片(Android(安卓)studio)
- android HTTPURLConnection解决不能访问HTTPs请求
- android lisetview的多列模版