标签:
package com.example.jsontextt;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
public class MainActivity extends Activity implements OnClickListener{
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", "开始获取数据");
tv=(TextView) findViewById(R.id.tv);
tv.setOnClickListener(this);
onLoad();
}
private void onLoad() {
// TODO Auto-generated method stub
String url="http://gandong.3gso.com:8080/Bemoved/" +
"userpublish_ReadUserBemoved?type=Userbemove&userId" +
"=f1e9de9447912cc00147913261c80005&Number" +
"=0&login_user_id" +
"=f1e9de944be05591014be2490cb5002e";
new HttpUtils().send(HttpMethod.GET, url, new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(ResponseInfo<String> arg0) {
// TODO Auto-generated method stub
String data=arg0.result;
Log.i("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", data);
tv.setText(data);
}
});
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.tv:
Intent intent=new Intent();
intent.setClass(MainActivity.this, MainActivity2.class);
startActivityForResult(intent, 123);
break;
default:
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == 201) {
Bundle bundle=data.getExtras();
String str=" ";
str=bundle.getString("edtinfo");
tv.setText(str);
Log.i("11111111111111111111111", str);
}else if(resultCode == 200){
}
if(requestCode ==123 ){
System.out.println("MainActivity传递过去的");
}else{
System.out.println("不是");
}
}
}
package com.example.jsontextt;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity2 extends Activity{
private EditText edt;
private Button but;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
edt=(EditText) findViewById(R.id.edt1);
but=(Button) findViewById(R.id.but);
but.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent(MainActivity2.this, MainActivity2.class);
intent.putExtra("edtinfo", edt.getText().toString());
setResult(201,intent);
MainActivity2.this.finish();
}
});
}
}
两个界面之间的信息传送通过 startActivityForResult()方法
标签:
原文地址:http://www.cnblogs.com/dpxf/p/4318867.html