Java tutorial
package com.autoparts.sellers.activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.view.View; import android.widget.AdapterView; import android.widget.EditText; import com.autoparts.sellers.R; import com.autoparts.sellers.network.HttpClientUtils; import com.autoparts.sellers.network.HttpResultHandler; import com.autoparts.sellers.network.ResponseModel; import com.autoparts.sellers.utils.CommonData; import com.autoparts.sellers.utils.Constants; import com.autoparts.sellers.utils.Utils; import org.apache.http.Header; import java.util.HashMap; import java.util.Map; /** * -- * Created by:Liuhuacheng * Created time:15-3-5 */ public class UserInfoEditActivity extends BaseActivity implements AdapterView.OnItemClickListener { private Context context; private String title = ""; private EditText mEditText; private int position = 0; private String hint = ""; /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.user_info_edit); super.onCreate(savedInstanceState); init(); } @Override public void onClick(View view) { super.onClick(view); switch (view.getId()) { case R.id.topBar_right_layout: getData(); break; } } private void init() { context = this; title = getIntent().getStringExtra("title"); setTitle(title); mEditText = (EditText) findViewById(R.id.mEditText); String content = getIntent().getStringExtra("content"); position = getIntent().getIntExtra("position", 0); if (position == 0) { hint = "??"; } else { hint = "?"; } mEditText.setHint(hint); mEditText.setText(content); mEditText.requestFocus(); CommonData.setEditCursor(mEditText); // ? mEditText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { setRightView(getString(R.string.confirm_ok), -1); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); } public void getData() { final String nam = mEditText.getText().toString().trim(); if (TextUtils.isEmpty(nam)) { Utils.showToastShort(context, ""); } else { showProgressDialog(); String url = Constants.USER_UP_ALL_INFO; Map<String, Object> params = new HashMap<String, Object>(); params.put("nam", ""); params.put("adr", ""); if (position == 0) { params.put("nam", nam); } if (position == 1) { params.put("adr", nam); } params.put("ton", ""); params.put("lat", ""); params.put("lp1", ""); params.put("lp2", ""); params.put("pic", ""); params.put("license", ""); params.put("agent", ""); HttpClientUtils.post(context, url, params, new HttpResultHandler() { @Override public void onResultFail(String message, int statusCode) { super.onResultFail(message, statusCode); } @Override public void onResultSuccess(Header[] headers, ResponseModel response, String message, int statusCode) { super.onResultSuccess(headers, response, message, statusCode); closeInputMethod(mEditText); Intent intent = new Intent(); intent.putExtra("content", nam); setResult(RESULT_OK, intent); finish(); } @Override public void onFinish() { super.onFinish(); disProgressDialog(); } }); } } // "id":"", // "nam":"??", // "adr":"??", // "ton":"?" // "lat":"", // "lp1":"??16?", // "lp2":"??16?", // "pic":"16?", // "license":"?16?", // "agent":"?16?" }