0

我的代码如下所示。如果登录成功或 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)
            {
            }
            }
    }
      }
4

1 回答 1

1

创建一个布尔变量并在成功提交时设置其值。然后在 showProgress() 中读取 run 方法中的布尔值

PayToLinkAccountProgressDialog.dismiss();
if(value)
{
 Toast.makeText(AgAppTransPayToLinkAccount.this, "Request    TimeOut " ,Toast.LENGTH_SHORT).show();
}
于 2012-09-24T06:26:20.363 回答