public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
httpUtils();
}
public void httpUtils(){
System.out.println("hehe");
OkHttpClient myOkHttpClient=new OkHttpClient();
Request request=new Request.Builder().url("http://www.hengboit.com/json/json_list.php?cid=27&num=20").build();
Call call=myOkHttpClient.newCall(request);
call.enqueue(new Callback() {
@Override
public void onResponse(Response arg0) throws IOException {
// TODO Auto-generated method stub
System.out.println("heihei");
String str=arg0.body().string();
@Override
public void onFailure(Request arg0, IOException arg1) {
// TODO Auto-generated method stub
}
});
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
httpUtils();
}
public void httpUtils(){
System.out.println("hehe");
OkHttpClient myOkHttpClient=new OkHttpClient();
Request request=new Request.Builder().url("http://www.hengboit.com/json/json_list.php?cid=27&num=20").build();
Call call=myOkHttpClient.newCall(request);
call.enqueue(new Callback() {
@Override
public void onResponse(Response arg0) throws IOException {
// TODO Auto-generated method stub
System.out.println("heihei");
String str=arg0.body().string();
System.out.println(str);
用Handler 在此方法中更新数据
}@Override
public void onFailure(Request arg0, IOException arg1) {
// TODO Auto-generated method stub
}
});
}
}