[android] 02_AsyncHttp框架

Android 4.0

AsyncHttp框架 

AsyncHttp框架 https://github.com/ 
搜索:async android
下载:https://github.com/loopj/android-async-http 
核心代码:
    /**
     * 获取文本内容
     * 
     * @param view
     */
    public void getContent(View view) {
        
        String path = et_path.getText().toString();
        if (TextUtils.isEmpty(path)) {
            Toast.makeText(getApplicationContext(), "路径不能为空", 0).show();
        }
        AsyncHttpClient sClient = new AsyncHttpClient();
        AsyncHttpResponseHandler responseHandler = new AsyncHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
                System.out.println("开始用AsyncHtp框架下载图片了。。。");
            }
            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                tv_content.setText(content);
            }
            @Override
            public void onFailure(int statusCode, Header[] headers,
                    Throwable error, String content) {
                super.onFailure(statusCode, headers, error, content);
                Toast.makeText(getApplicationContext(), "请求失败。。。", 0).show();
                error.printStackTrace();
            }
        };
        sClient.get(path, responseHandler); // 使用该框架,不用new Thread,内部已经实现了。。。
    }
结果:

源码: