android asynchttpclientpost怎么返回数据
答案:2 悬赏:10 手机版
解决时间 2021-02-11 01:25
- 提问者网友:人生佛魔见
- 2021-02-10 04:00
android asynchttpclientpost怎么返回数据
最佳答案
- 五星知识达人网友:杯酒困英雄
- 2021-02-10 04:15
首先下载AsyncHttpClient的库文件,可以自行搜索
测试的Activity,用到了RequstClient,
LoadCacheResponseLoginouthandler,LoadDatahandler三个重写的类
java代码
package com.example.asynchttpclienttest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
import com.loopj.android.http.RequestParams;
public class MainActivity extends Activity {
private TextView test;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
test = (TextView) findViewById(R.id.test);
System.out.println("拉拉");
RequestParams param = new RequestParams();
param.put("id", 1 + "");
RequstClient.get(
"/xiaoxiao2/ColumnServletAndroid",
param, new LoadCacheResponseLoginouthandler(MainActivity.this,
new LoadDatahandler() {
@Override
public void onStart() {
super.onStart();
test.setText("开始拉去数据");
}
@Override
public void onSuccess(String data) {
super.onSuccess(data);
test.setText(data);
System.out.println("拉倒的数据" + data);
}
@Override
public void onFailure(String error, String message) {
super.onFailure(error, message);
test.setText("错误的数据" + message);
}
@Override
public void onFinish() {
super.onFinish();
}
}));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
接口:
java代码
package com.example.asynchttpclienttest;
public class LoadDatahandler {
public void onStart() {};
public void onLoadCaches(String data) {};
public void onSuccess(String data) {};
public void onFailure(String error, String message) {};
public void onFinish() {};
}
测试的Activity,用到了RequstClient,
LoadCacheResponseLoginouthandler,LoadDatahandler三个重写的类
java代码
package com.example.asynchttpclienttest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
import com.loopj.android.http.RequestParams;
public class MainActivity extends Activity {
private TextView test;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
test = (TextView) findViewById(R.id.test);
System.out.println("拉拉");
RequestParams param = new RequestParams();
param.put("id", 1 + "");
RequstClient.get(
"/xiaoxiao2/ColumnServletAndroid",
param, new LoadCacheResponseLoginouthandler(MainActivity.this,
new LoadDatahandler() {
@Override
public void onStart() {
super.onStart();
test.setText("开始拉去数据");
}
@Override
public void onSuccess(String data) {
super.onSuccess(data);
test.setText(data);
System.out.println("拉倒的数据" + data);
}
@Override
public void onFailure(String error, String message) {
super.onFailure(error, message);
test.setText("错误的数据" + message);
}
@Override
public void onFinish() {
super.onFinish();
}
}));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
接口:
java代码
package com.example.asynchttpclienttest;
public class LoadDatahandler {
public void onStart() {};
public void onLoadCaches(String data) {};
public void onSuccess(String data) {};
public void onFailure(String error, String message) {};
public void onFinish() {};
}
全部回答
- 1楼网友:雪起风沙痕
- 2021-02-10 05:18
你说呢...
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯