您好我正在尝试从我的编辑文本中检索某些值。
首先,当我没有输入任何内容时,我敬酒以通知我没有文本输入并且它有效!
然后当我输入文本时,这一次,祝酒词再次出现!当有文本输入时..
显示 toast / 检索文本的代码:
public class ResetPassword extends Activity implements OnClickListener{
// Creating JSON Parser object
JSONParser jParser = new JSONParser();
private static final String TAG_PASSWORD = "password";
private static final String TAG_SUCCESS = "success";
private static final String TAG_PASS = "pass";
String enteredPassword;
String changedPass;
String currentPass;
//String password;
// products JSONArray
JSONArray products = null;
//private static String url_member_login = "http://10.0.2.2/android_connect/get_login.php";
private static String url_login = "http://10.0.2.2/android_connect/change_password.php";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.password);
this.setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
ImageButton home = (ImageButton)findViewById(R.id.btn_home);
home.setOnClickListener(this);
Button save = (Button) findViewById(R.id.btn_save);
save.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
if (currentPass != null && changedPass != null)
{
new ResetPass().execute();
}
else
{
/** A TEMPORARY DISPLAY FROM CUSTOM TOAST **/
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.customtoast,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text1 = (TextView) layout.findViewById(R.id.txt_engRecords);
TextView text2 = (TextView) layout.findViewById(R.id.txt_chiRecords);
text1.setText("Feature is temporarily unavailable");
text2.setText("Unable to update ");
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
}});
}
/**
* Background Async Task to Save product Details
* */
class ResetPass extends AsyncTask<String, String, String> {
/**
* Saving product
* */
protected String doInBackground(String... args) {
// check json success tag
try {
// Building Parameters
EditText currentPassword = (EditText) findViewById(R.id.edit_current);
currentPass = currentPassword.getText().toString();
EditText newPassword = (EditText) findViewById(R.id.edit_new);
changedPass = newPassword.getText().toString();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(TAG_PASSWORD, changedPass));
// sending modified data through http request
// Notice that update product url accepts POST method
JSONObject json = jParser.makeHttpRequest(url_login,
"GET", params);
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
finish();
} else {
// failed to update product
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}