gpt4 book ai didi

java - 如果 Android 中的 Edittext 内部有错误,则发送按钮正在发送数据

转载 作者:行者123 更新时间:2023-12-01 12:59:28 26 4
gpt4 key购买 nike

我使用了两个编辑文本框,其中我对电子邮件的编辑文本框进行了验证,并确认电子邮件地址我使用了文本匹配器,并且验证对我来说工作正常,当我检查在编辑文本中输入的数据时没有问题当我单击发送按钮时进入数据库,如果有错误,以及如何在任何文本框中出现错误时禁用该按钮,在更正错误后,它必须部署输入到数据库中的数据,否则它必须禁用按钮我需要输入一些内容来阻止发送按钮

我已经在这里对 edittext3 和 edittext4 进行了验证,因此如果此按钮中存在任何错误,则必须禁用我必须包含的位置

send.setEnabled(false);
send.setEnabled(true);

我必须在此代码中包含上述方法

edittext3.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {

}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {

}

@Override
public void afterTextChanged(Editable s) {

Is_Valid_Email_Address(edittext3);
}

public void Is_Valid_Email_Address(EditText edittext3) {
if (edittext3.getText().toString() == null) {
edittext3.setError("Invalid Email Address");
valid_email = null;
} else if (isEmailValid(edittext3.getText().toString()) == false) {
edittext3.setError("Invalid Email Address");
valid_email = null;
} else if(edittext3.length() == 0 || edittext3.equals("") || edittext3 == null || "".equals(edittext3.getText().toString())) {
valid_email = null;
}else {
valid_email = edittext3.getText().toString();
}
}
});

edittext4.addTextChangedListener(new TextWatcher() {

@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {


}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {


}

@Override
public void afterTextChanged(Editable s) {

Is_Valid_Confirm_Address(edittext4);
}


public void Is_Valid_Confirm_Address(EditText edittext4) {
if (edittext4.getText().toString() == null) {
edittext4.setError("Invalid Email Address");
valid_confirm = null;
} else if (isEmailValid(edittext4.getText().toString()) == false) {
edittext4.setError("Invalid Email Address");
valid_confirm = null;
} else if (edittext4.getText().toString().equals(edittext3.getText().toString())) {

valid_confirm = edittext4.getText().toString();
} else if(edittext4.length() == 0 || edittext4.equals("") || edittext4 == null || "".equals(edittext4.getText().toString())) {
valid_confirm = null;
} else {
edittext4.setError("Confirm Email is Not Matching");
valid_confirm = null;
}

}
});

//如果有任何错误,则按钮必须变为禁用或启用才能将其添加到数据库

    Button send= (Button)findViewById(R.id.send_email);
send.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

String email = edittext3.getText().toString();
String confirm = edittext4.getText().toString();


ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

nameValuePairs.add(new BasicNameValuePair("email_address",email));
nameValuePairs.add(new BasicNameValuePair("confirm_email_address",confirm));

try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.132/Android_App/Sendata.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();

Log.e("log_tag", "connection success ");
Toast.makeText(getApplicationContext(), "contact you shortly.", Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Log.e("log_tag", "Error in http connection "+e.toString());
Toast.makeText(getApplicationContext(), "Connection fail", Toast.LENGTH_SHORT).show();
}
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
Intent i = new Intent(getBaseContext(),SecondActivity.class);
startActivity(i);
}
is.close();

result=sb.toString();
}
catch(Exception e)
{
Log.e("log_tag", "Error converting result "+e.toString());
}
try
{
JSONObject json_data = new JSONObject(result);
CharSequence w= (CharSequence) json_data.get("result");

Toast.makeText(getApplicationContext(), w, Toast.LENGTH_SHORT).show();
}
catch(JSONException e)
{
Log.e("log_tag", "Error parsing data "+e.toString());
Toast.makeText(getApplicationContext(), "JsonArray fail", Toast.LENGTH_SHORT).show();
}

}
});
}

private boolean isEmailValid(String email) {
return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
}

有谁知道请帮助我提前谢谢

最佳答案

public void afterTextChanged(Editable s) {

if(Is_Valid_Email_Address(edittext3.getText().toString())){
send.setEnabled(true);
}else{
send.setEnabled(false);
}
}

也许试试这个?也将其应用于 edittext4。

试试这个方法。

关于java - 如果 Android 中的 Edittext 内部有错误,则发送按钮正在发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23632185/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com