2013-09-23 42 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

相關問題