我的代码如下所示。如果成功登录或15秒没有登录,它总是显示请求超时消息。如果提交成功,则始终打印“请求超时”Toast消息。如何停止打印“请求超时”吐司?它只应在申请流程未成功15秒时打印。
import android.widget.TextView;
import android.widget.Toast;
public class AgAppTransPayToLinkAccount extends Activity {
TextView lblPTLWelcomeToPayToLinkAccountPage;
TextView lblPTLPinno;
TextView lblPTLAmount;
EditText txtPTLpinno;
EditText txtPTLamount;
Button btnPTLsubmit;
Button clearPTLButton;
Button btnPTLgoback;
boolean value=true;
String sms;
ProgressDialog PayToLinkAccountProgressDialog = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.agapptranspaytolinkaccount);
sms=LoginScreen.item.toString();
lblPTLPinno = (TextView) findViewById(R.id.lblPTLPinno);
lblPTLPinno.setText("PIN Number :" );
txtPTLpinno=(EditText) findViewById(R.id.txtPTLpinno);
lblPTLAmount = (TextView) findViewById(R.id.lblPTLAmount);
lblPTLAmount.setText("Amount :" );
txtPTLamount=(EditText) findViewById(R.id.txtPTLamount);
btnPTLsubmit =(Button) findViewById(R.id.btnPTLsubmit);
btnPTLsubmit.setTextColor(getResources().getColor(R.color.text_color_blue));
btnPTLsubmit.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
showProgress();
submitPTLA();
}
});
clearPTLButton =(Button) findViewById(R.id.clearPTLButton);
clearPTLButton.setTextColor(getResources().getColor(R.color.text_color_blue));
clearPTLButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
txtPTLpinno.setText("");
txtPTLamount.setText("");
}
});
btnPTLgoback=(Button) findViewById(R.id.btnPTLgoback);
btnPTLgoback.setTextColor(getResources().getColor(R.color.text_color_blue));
btnPTLgoback.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
finish();
}
});
}
private void submitPTLA() {
String message;
String mobilenumber= LoginScreen.smsmobileno;
if (txtPTLpinno.getTextSize()==0 ||txtPTLamount.getTextSize()==0)
{
AlertDialog.Builder altDialog= new AlertDialog.Builder(this);
altDialog.setMessage("Please Enter Complete Information!");
}
else
{
if (( sms.compareTo("SMS")==0))
{
SmsManager smsmanager = SmsManager.getDefault();
message="AGLIA"+AgAppHelperMethods.varMobileNo+AgAppHelperMethods.varMobileNo+
txtPTLpinno.g
etText().toString()+txtPTLamount.getText().toString();
smsmanager.sendTextMessage(mobilenumber, null, message, null,null);
}
else
{
Intent j = new
Intent(AgAppTransPayToLinkAccount.this,AgAppTransPTLAResponse.class);
Bundle bundle = new Bundle();
bundle.putString("pinno",txtPTLpinno.getText().toString());
bundle.putString("amount",txtPTLamount.getText().toString());
j.putExtras(bundle);
startActivity(j);
value=false;
PayToLinkAccountProgressDialog.dismiss();
}
}
}
private void showProgress()
{
PayToLinkAccountProgressDialog =
ProgressDialog.show(AgAppTransPayToLinkAccount.this,null, "Processing please
wait...", true);
if (PayToLinkAccountProgressDialog != null) {
try
{
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run()
{
PayToLinkAccountProgressDialog.dismiss();
if(value)
{
Toast.makeText(AgAppTransPayToLinkAccount.this, "Request
TimeOut " , Toast.LENGTH_SHORT).show();
}
}
}, 15000); // <--- here is the time adjustment.
}
catch (Exception e)
{
}
}
}
}
答案 0 :(得分:1)
创建一个布尔变量并在succesffull提交上设置其值。 然后在showProgress()
中读取runin方法中的boolean valuePayToLinkAccountProgressDialog.dismiss();
if(value)
{
Toast.makeText(AgAppTransPayToLinkAccount.this, "Request TimeOut " ,Toast.LENGTH_SHORT).show();
}