首页>代码>生鲜o2o配送开源系统,包括Android源码+SSH后台管理系统>/生鲜O2O源码/android端/freshO2O/app/src/main/java/com/freshO2O/AddressEditActivity.java
package com.freshO2O;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;
import com.freshO2O.app.MyApplication;
import com.freshO2O.bean.Configer;
import com.freshO2O.entity.Receiveaddr;
import com.freshO2O.utils.ToastUtil;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class AddressEditActivity extends Activity {
private TextView userAddBack;
private TextView edit;
private EditText uname;
private EditText phoneText;
private EditText addressText;
Receiveaddr a;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_address_edit);
userAddBack = (TextView) findViewById(R.id.user_add_back);
ClickListener cl = new ClickListener();
userAddBack.setOnClickListener(cl);
edit = (TextView) findViewById(R.id.edit);
edit.setOnClickListener(cl);
uname = (EditText) findViewById(R.id.username);
phoneText = (EditText) findViewById(R.id.phone);
addressText = (EditText) findViewById(R.id.address);
Intent intent = getIntent();
Bundle bundle = intent.getBundleExtra("key");
a = (Receiveaddr)bundle.getSerializable("addr");
// ToastUtil.showToast(this, a.getAddress());
//
uname.setText(a.getUsername());
phoneText.setText(a.getPhone());
addressText.setText(a.getAddress());
}
List<NameValuePair> params;
private String result;
private String myurl;
//增加用户
private void addUser(){
String username = uname.getText().toString();
String phone = phoneText.getText().toString();
String address = addressText.getText().toString();
if(null == username || username.length() == 0){
ToastUtil.showToast(this, "收货人不能为空");
return;
}
if(null == phone || phone.length() == 0){
ToastUtil.showToast(this, "手机不能为空");
return;
}
if(null == address || address.length() == 0){
ToastUtil.showToast(this, "地址不能为空");
return;
}
params =new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("account", MyApplication.user.getAccount()));
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("phone", phone));
params.add(new BasicNameValuePair("address", address));
params.add(new BasicNameValuePair("id", String.valueOf(a.getId())));
myurl = Configer.SERVER_HOST+"/receiveaddrEdit.action";
new Thread(getJson).start();
}
Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.what == 0x00) {
Log.v("PostGetJson", "" + result);
if(null != result){
try {
JSONObject json= new JSONObject(result);
String re = (String)json.get("result");
ToastUtil.showToast(AddressEditActivity.this, "修改成功");
// execute(re);
} catch (JSONException e) {
e.printStackTrace();
}
}
} else if (msg.what == 0x01) {
Toast.makeText(getApplicationContext(), "获取失败",
Toast.LENGTH_LONG).show();
}
}
};
private Runnable getJson=new Runnable()
{
public void run() {
// TODO Auto-generated method stub
try
{
result=GetJson(myurl, params);
handler.sendEmptyMessage(0x00);
}
catch(Exception e)
{
handler.sendEmptyMessage(0x01);
}
}
};
/**
* 发送post请求获取json字符串
* @param url 网站
* @param params 参数List
* @return json字符串
*/
private String GetJson(String url, List<NameValuePair> params) {
HttpPost httpRequest = new HttpPost(url);
/*
* NameValuePair实现请求参数的封装
*/
String strResult = null;
/* 添加请求参数到请求对象 */
HttpParams httpParameters1 = new BasicHttpParams();
HttpConnectionParams
.setConnectionTimeout(httpParameters1, 10 * 1000);
HttpConnectionParams.setSoTimeout(httpParameters1, 10 * 1000);
//设置超时参数
try {
httpRequest.setParams(httpParameters1);
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
/* 发送请求并等待响应 */
HttpResponse httpResponse = new DefaultHttpClient()
.execute(httpRequest);
/* 若状态码为200 ok */
if (httpResponse.getStatusLine().getStatusCode() == 200)
{
/* 读返回数据 */
strResult = EntityUtils.toString(httpResponse.getEntity());
}
else
{
// 获取出现错误
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return strResult;
}
//事件点击监听器
private final class ClickListener implements OnClickListener{
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.user_add_back:
AddressEditActivity.this.finish();
break;
case R.id.edit:
addUser();
break;
default:
break;
}
}
}
}
最近下载更多
tianya_hailang LV1
7月8日
ewan007 LV30
2024年3月19日
晴曛 LV6
2023年12月29日
xiaoluo_123 LV3
2023年6月4日
2775645521 LV7
2023年5月24日
龙门客栈 LV9
2023年3月31日
Sunyibo LV1
2023年2月10日
东方之珠_1628 LV6
2023年1月7日
zhaoyangwfd LV17
2022年10月8日
微信网友_6094303684497408 LV4
2022年8月30日
最近浏览更多
一个神秘人 LV1
10月24日
Li123450
10月18日
暂无贡献等级
夜起星河 LV8
8月5日
微信网友_6956978011000832 LV2
7月26日
tianya_hailang LV1
7月8日
浙江螃蟹 LV7
7月2日
刘先生-OL LV13
4月8日
哪里的完整版 LV8
4月1日
sjwc88 LV4
2024年12月15日
微信网友_6779541724286976
2024年11月15日
暂无贡献等级

