12 Android AsyncHttpClient 的简单使用

package com.sd.ert;

import java.io.IOException;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class TBtnActivity extends Activity {
    /** Called when the activity is first created. */
	private TextView textview;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        textview=(TextView)findViewById(R.id.textview1);
       
    }
    
    public void myClick(View view)
    {
    	 initView("http://m.weather.com.cn/data/101010100.html");
    	Toast.makeText(TBtnActivity.this, "123abc", Toast.LENGTH_LONG).show();
        Log.d("ERROcuowu","______________cas");
    }
    
    public void initView(String url)
    {
    	TextView textView=(TextView)findViewById(R.id.textview1);
    	
    	RequestParams params=new RequestParams();
    	params.put("id", 1+"");
    	AsyncHttpClient ahc=new AsyncHttpClient();
    	ahc.get(url, new AsyncHttpResponseHandler()
    	{
    		public void onSuccess(String reult)
    		{
    			System.out.println(reult);
    			textview.setText(reult);
    			
    		}
    		
    		public void onFailure(Throwable e)
    		{
    			Log.d("LOG", ""+e);
    		}
    	}
       );
    }
}

你可能感兴趣的:(12 Android AsyncHttpClient 的简单使用)