happydictionary
2015-07-04 12:59
375 查看
1.
从界面看一共用了三个控件EditText,Button,WebView。其实是四个,是当我们查询内容为空的时候用来提示的Toast控件。我们在EditText输入查询内容,这里包括中文,英文。然后通过参数的形式,从http://dict.youdao.com/m取出数据把结果存放在WebView里
2.主要代码:
public class MainActivity extends Activity {
private Button btu,clear;
private WebView wv;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findView();
}
private void findView() {
// TODO Auto-generated method stub
btu = (Button) findViewById(R.id.btu);
clear = (Button) findViewById(R.id.clear);
et = (EditText) findViewById(R.id.et);
wv = (WebView) findViewById(R.id.wb);
btu.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
String str = (et.getText().toString());
str=str.trim();
if(str.length()==0){
Toast.makeText(MainActivity.this, "输入为空", Toast.LENGTH_SHORT).show();
}else{
String s = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&q="+str;
wv.getSettings().setJavaScriptEnabled(true);
wv.setWebViewClient(new MyWebViewClient());
wv.loadUrl(s);
}
}
});
clear.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
et.setText("");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
从界面看一共用了三个控件EditText,Button,WebView。其实是四个,是当我们查询内容为空的时候用来提示的Toast控件。我们在EditText输入查询内容,这里包括中文,英文。然后通过参数的形式,从http://dict.youdao.com/m取出数据把结果存放在WebView里
2.主要代码:
public class MainActivity extends Activity {
private Button btu,clear;
private WebView wv;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findView();
}
private void findView() {
// TODO Auto-generated method stub
btu = (Button) findViewById(R.id.btu);
clear = (Button) findViewById(R.id.clear);
et = (EditText) findViewById(R.id.et);
wv = (WebView) findViewById(R.id.wb);
btu.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
String str = (et.getText().toString());
str=str.trim();
if(str.length()==0){
Toast.makeText(MainActivity.this, "输入为空", Toast.LENGTH_SHORT).show();
}else{
String s = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&q="+str;
wv.getSettings().setJavaScriptEnabled(true);
wv.setWebViewClient(new MyWebViewClient());
wv.loadUrl(s);
}
}
});
clear.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
et.setText("");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
相关文章推荐
- [Android L or M ]解除SwitchPreference与Preference的绑定事件
- cocos2dx v3环境配置
- 添加背景音乐
- iOS SDK详解之IBInspectable和IB_DESIGNABLE-Storyboad动态刷新
- ios多手势事件
- android studio教程及android环境搭建
- stitch image app (Qt)
- [Android L]关于Android L的Service启动问题
- (转)ios获取设备系统信息
- Android Studio 快捷键整理分享
- iOS开发—Swift时间戳转换方法
- Android实现音乐后台播放
- 关于jQuery方法解析(一)append-参数设置问题
- 转载]IOS LBS功能详解[0](获取经纬度)[1](获取当前地理位置文本 )
- Objective-C Json 使用
- Android中系统存储 Settings
- APP产品经理的第90天
- Android IOS WebRTC 音视频开发总结(三一)-- 自定义传输实现一对多
- Android ListView使用详解
- 暑假计划