gpt4 book ai didi

android - 在不调用 Dismiss 的情况下关闭警报对话框

转载 作者:行者123 更新时间:2023-11-29 21:21:57 33 4
gpt4 key购买 nike

在我的程序中,我正在为一个空编辑文本显示 Toast,该编辑文本在我的对话框中以及上传按钮,现在谈谈我的程序和问题

喜欢:

  1. PersonName字段不能留空

  2. 如果 PersonName 字段 为空,则显示 Toast(每当用户在警告对话框

  3. 点击“上传”按钮)
  4. 如果不调用dismiss,它会关闭我的 AlertDialog

在我的 AlertDialog 中,我有大约 4 个 EditTexts3 个按钮 和一些其他小部件。 p>

UploadActivity.java:-

private boolean SaveData() {                        

final AlertDialog.Builder ad = new AlertDialog.Builder(UploadActivity.this);
ad.setTitle("StreamReader");
ad.setIcon(android.R.drawable.btn_star_big_on);
ad.setPositiveButton("Close", null);
if(editPersonName.getText().length() == 0)
{
Toast.makeText(getApplicationContext(), "Person Name field cannot be left blank", Toast.LENGTH_LONG).show();
return false ;
}
String
url = "http://domain.tld/sendData.jsp";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("sImageName", editImageName.getText().toString()));

String resultServer = getHttpPost(url,params);
Log.d("Entire string::", " " + resultServer);
/*** Default Value ***/
String strStatusID = "0";
String strError = "Data Stored to Server";
JSONObject c;
try {
c = new JSONObject(resultServer);
strStatusID = c.getString("StatusID");
strError = c.getString("Message");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// prepare save data
if(strStatusID.equals("0"))
{
Toast.makeText(getApplicationContext(), strError.toString(), Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(), "Data Uploaded Successfully!", Toast.LENGTH_LONG).show();
}
return true;
}

最佳答案

在调用 SaveData 方法之前验证您的编辑文本。并从 SaveData 中删除验证码:

所以像这样处理点击事件:

uploadButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {

if(editPersonName.getText().length() == 0)
{
Toast.makeText(getApplicationContext(), "Person Name field cannot be left blank", Toast.LENGTH_LONG).show();

}
else
{
SaveData();
}
}

现在您的 SaveData 将如下所示:

private void SaveData() {    

String
url = "http://domain.tld/sendData.jsp";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("sImageName", editImageName.getText().toString()));

String resultServer = getHttpPost(url,params);
Log.d("Entire string::", " " + resultServer);
/*** Default Value ***/
String strStatusID = "0";
String strError = "Data Stored to Server";
JSONObject c;
try {
c = new JSONObject(resultServer);
strStatusID = c.getString("StatusID");
strError = c.getString("Message");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

// prepare save data
if(strStatusID.equals("0"))
{
Toast.makeText(getApplicationContext(), strError.toString(), Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(), "Data Uploaded Successfully!", Toast.LENGTH_LONG).show();
}
}

关于android - 在不调用 Dismiss 的情况下关闭警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20627756/

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