2013-09-23 22 views
0

这里之前完成的我目前AddDebt.java节我在看:要求EditView中框被移动到另一个活动

public void ButtonOnClick(View v) { 
     Intent intent = new Intent(this, MainActivity.class); 

     EditText debtors = (EditText) findViewById(R.id.editDebtor); 
     String debtor = debtors.getText().toString(); 

     EditText myEdit = (EditText) findViewById(R.id.editBalance); 
     String myEditValue = myEdit.getText().toString(); 
     double loanAmount = Double.parseDouble(myEditValue); 

     EditText myEdit2 = (EditText) findViewById(R.id.editRate); 
     String myEditValue2 = myEdit2.getText().toString(); 
     double interestRate = Double.parseDouble(myEditValue2); 

     EditText myEdit3 = (EditText) findViewById(R.id.editTerm); 
     String myEditValue3 = myEdit3.getText().toString(); 
     Double loanPeriod = Double.parseDouble(myEditValue3); 

     double r = interestRate/1200; 
     double r1 = Math.pow(r+1,loanPeriod); 

     double editMnthlypmt = (double) ((r+(r/(r1-1))) * loanAmount); 
     DecimalFormat df = new DecimalFormat("#.##");  
     editMnthlypmt = Double.valueOf(df.format(editMnthlypmt)); 

     TextView textMnthlypmt = (TextView)findViewById(R.id.textMntlypmt); 

     switch (v.getId()) { 

     case R.id.calculate: 
      textMnthlypmt.setText("" + String.valueOf(editMnthlypmt)); 
     break; 
     case R.id.addDebt: 
     if(debtors.getText().length() == 0){ 
       Toast.makeText(getApplicationContext(), "Please enter debtors value", Toast.LENGTH_SHORT).show(); 
       debtors.requestFocus(); 
      }else if(myEdit.getText().length() == 0){ 
       Toast.makeText(getApplicationContext(), "Please enter myedit value", Toast.LENGTH_SHORT).show(); 
       myEdit.requestFocus(); 
      } 
      else 
      { 
      //Transferring data to MainActivity 
      intent.putExtra("debtor",debtor); 
      intent.putExtra("loanAmount",loanAmount); 
      intent.putExtra("editMnthlypmt",editMnthlypmt); 

      //Next moves back to MainActivity 
      startActivity(intent); 
      } 
     break; 
    } 
} 

时“的情况下R.id.addDebt:”被选择,我想以确保editDebtor,editBalance,editRate和editTerm全部完成。如果不是,我希望它把焦点放在最不完整的最上面的框中。如果完成,我希望它切换到我的意图。

有任何建议。

+0

在这个意义上完成输入或不?如果输入或不是意味着检查空条件,如if(myEditValue.trim()。length> 0) – Pinki

回答

1

试试这个,

case R.id.addDebt: 
if(debtors.getText().length() == 0){ 
    Toast.makeText(Activityname, "Please enter debtors value", Toast.LENGTH_SHORT).show(); 
    debtors.requestFocus(); 
}else if(myEdit.getText().length() == 0){ 
    Toast.makeText(Activityname, "Please enter myedit value", Toast.LENGTH_SHORT).show(); 
    myEdit.requestFocus(); 
}else if()....... 

}else{ 
//Add your Intent here 
} 
+0

我编辑了最接近的主脚本我可以找出你的,它给出了一个致命的错误。该错误在第67行,即紧接在loanAmount的添加之后的行。我猜测是因为它不能将NULL解析为double。这里有什么建议? – jpgerb

相关问题