1

我的代码不打印空编辑文本 itry trim Stirng .length==00 但在我的代码中没有工作帽错误?我的代码如何在 sumbit 查询之前检查edittext是否为空

如果edittext为空,我想在提交方法之前检查?如果为空,则打印 toast 消息

public class AgAppTransPayExternalAccount  extends Activity {

TextView lblTPEAWelcomeToPayExternalAccountPage;
TextView lblTPEAOtherAccount;
TextView lblTPEAPinno;
TextView lblTPEAAmount;

EditText txtTPEAotheraccount;

EditText txtTPEApinno;

EditText txtTPEAamount;


Button btnTPEAsubmit;
Button clearTPEAButton;
Button btnTPEAgoback;
String sms;
public  static ProgressDialog PayExternalAccountProgressDialog = null;
public  static  boolean value=true;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.agapptranspayexternalaccount);
    sms=LoginScreen.item.toString();

    /*

    lblTPEAWelcomeToPayExternalAccountPage = (TextView)  
  findViewById(R.id.lblTPEAWelcomeToPayExternalAccountPage);
    lblTPEAWelcomeToPayExternalAccountPage.setText("Welcome To Pay External  
 Account Page");


   lblTPEAWelcomeToPayExternalAccountPage.setTextColor(getResources().getColor
   (R.color.text_color_black));
    */

    lblTPEAOtherAccount = (TextView) findViewById(R.id.lblTPEAOtherAccount);
    lblTPEAOtherAccount.setText("Other Account :");

    txtTPEAotheraccount=(EditText) findViewById(R.id.txtTPEAotheraccount);



    lblTPEAPinno = (TextView) findViewById(R.id.lblTPEAPinno);
    lblTPEAPinno.setText("PIN Number :");

    txtTPEApinno=(EditText) findViewById(R.id.txtTPEApinno);

    lblTPEAAmount = (TextView) findViewById(R.id.lblTPEAAmount);
    lblTPEAAmount.setText("Amount :");

    txtTPEAamount=(EditText) findViewById(R.id.txtTPEAamount);

    btnTPEAsubmit=(Button) findViewById(R.id.btnTPEAsubmit);

  btnTPEAsubmit.setTextColor(getResources().getColor(R.color.text_color_blue));

    clearTPEAButton=(Button) findViewById(R.id.clearTPEAButton);

  clearTPEAButton.setTextColor(getResources().getColor(R.color.text_color_blue));

    btnTPEAgoback=(Button) findViewById(R.id.btnTPEAgoback);

  btnTPEAgoback.setTextColor(getResources().getColor(R.color.text_color_blue));


    clearTPEAButton.setOnClickListener(new OnClickListener()
    {
    public void onClick(View v)

    {
        txtTPEAotheraccount.setText("");
        txtTPEApinno.setText("");
        txtTPEAamount.setText("");

            }
      });

  btnTPEAgoback.setOnClickListener(new OnClickListener()
    {
    public void onClick(View v)

    {
        finish();

             }
       });
  btnTPEAsubmit.setOnClickListener(new OnClickListener()
    {
    public void onClick(View v)

    {
        String tpeapinemptycheck = txtTPEApinno.getText().toString();
        String otheraccountemptycheck =  
                    lblTPEAOtherAccount.getText().toString();
        String amountemptycheck = txtTPEAamount.getText().toString();

         if  (tpeapinemptycheck.trim().equals("")|| 
  (otheraccountemptycheck.trim().equals("")) ||(amountemptycheck.trim().equals("")))
         {
         Toast.makeText(getApplicationContext(), "Please Enter   
   Correct Information", Toast.LENGTH_LONG).show();
                  } 

         else
                    showProgress();
                submitPEA();

    }
    });

     }

private void submitPEA() {
     String message;
        String mobilenumber= LoginScreen.smsmobileno;

         if (( sms.compareTo("SMS")==0))
         {
     SmsManager smsmanager = SmsManager.getDefault();

message="AGPEA"+AgAppHelperMethods.varMobileNo+AgAppHelperMethods.

  arMobileNo+txtTPEAotheraccount.getText().toString()+AgAppHelperMethods.
 varMobileNo+txtTPEApinno.getText().toString()+txtTPEAamount.getText().toString();
     smsmanager.sendTextMessage(mobilenumber, null, message, null, null);
         }
 else
    { 

         Intent j = new Intent(AgAppTransPayExternalAccount.this, AgAppTransPEAResponse.class);


        Bundle bundle = new Bundle();
         bundle.putString("txtTPEApinno", txtTPEApinno.getText().toString());


     bundle.putString("txtTPEAotheraccount",txtTPEAotheraccount.getText().toString());
         bundle.putString("txtTPEAamount",txtTPEAamount.getText().toString());
         j.putExtras(bundle);


        startActivity(j);
        value=false;
        PayExternalAccountProgressDialog.dismiss();

 }


  }
private void showProgress()
{    

    PayExternalAccountProgressDialog = 
ProgressDialog.show(AgAppTransPayExternalAccount.this,null, "Processing please 
    wait...", true);    
    if (PayExternalAccountProgressDialog != null) {
        try
        {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable()
        {
        @Override
        public void run()
        {
            PayExternalAccountProgressDialog.dismiss();
            if(value)
            {
            Toast.makeText(AgAppTransPayExternalAccount.this, "Request 
      TimeOut " , Toast.LENGTH_SHORT).show();
            }
        }
        }, 15000); // <--- here is the time adjustment.
        }
        catch (Exception e)
        {
        }
        }
}
         }
4

3 回答 3

4

你的代码是对的,只有在 else 条件下缺少这个是{ }大括号,尝试如下,

if  (tpeapinemptycheck.trim().equals("")|| 
        (otheraccountemptycheck.trim().equals("")) ||(amountemptycheck.trim().equals("")))
{

    Toast.makeText(getApplicationContext(), "Please Enter   
            Correct Information", Toast.LENGTH_LONG).show();


} 

else
{ // add this
     showProgress();
     submitPEA();
} // add this

仅仅因为您没有添加那些{ }大括号,您的控件就进入了submitPEA()方法。

于 2012-09-25T09:08:50.130 回答
1

像这样试试

edit_text.getText().toString().trim().equals("");
于 2012-09-25T09:09:15.813 回答
-1

创建一个字符串变量say x; 现在,如果 et 是您的 EditText 字段,请使用:

x = et.getText().toString();

如果 EditText 字段中有任何文本,它将被传递给字符串 x。现在检查字符串 x 是否不为空或不包含任何内容

if(x.matches(""))
{
//your code here
}
else
{
//the counter action you'll take
}

通过这种方式,您可以检查您即将在数据库中输入的条目是否为空。快乐编码。

于 2012-09-25T09:13:52.120 回答