0

这是我正在查看的当前 AddDebt.java 部分:

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;
    }
}

when "case R.id.addDebt:" is being chosen, I want to ensure that editDebtor, editBalance, editRate, and editTerm are all completed. 如果没有,我希望它把焦点放在最不完整的盒子上。如果完成,我希望它切换到我的意图。

有什么建议么。

4

1 回答 1

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
 }
于 2013-09-23T07:09:39.637 回答