您的位置:首页 > 移动开发

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;

    }

   
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: