英文:
Android: How to set text of radio button into an Integer?
问题
我需要从 RadioGroup 中检索值,并根据贷款期限将 Radio 按钮上的文本设置为整数。
**PurchaseActivity.java**
Auto mAuto;
// 要传递到贷款活动的数据
String loanReport;
String monthlyPayment;
// 布局输入引用
EditText carPriceET;
EditText downPayET;
RadioGroup loanTermRG;
private void collectAutoInputData() {
// 任务 1: 设置汽车价格
mAuto.setPrice((double) Integer.valueOf(carPriceET.getText()
.toString()));
// 任务 2: 设置首付款
mAuto.setDownPayment((double)
Integer.valueOf(downPayET.getText()
.toString()));
// 任务 3: 设置贷款期限
Integer radioId = loanTermRG.getCheckedRadioButtonId();
RadioButton term = (RadioButton) findViewById(radioId);
mAuto.setLoanTerm(term.getText().toString());
}
英文:
I am needing to retrieve the values from a RadioGroup and set the Text on the Radio Buttons to an Integer based on the loan term.
PurchaseActivity.java
Auto mAuto;
// THE DATA TO BE PASSED TO THE LOAN ACTIVITY
String loanReport;
String monthlyPayment;
// LAYOUT INPUT REFERENCES
EditText carPriceET;
EditText downPayET;
RadioGroup loanTermRG;
private void collectAutoInputData() {
// TASK 1: SET THE CAR PRICE
mAuto.setPrice ((double) Integer.valueOf(carPriceET.getText()
.toString()));
//TASK 2: SET THE DOWN PAYMENT
mAuto.setDownPayment((double)
Integer.valueOf(downPayET.getText()
.toString()));
//TASK 3 SET THE LOAN TERM
Integer radioId = loanTermRG.getCheckedRadioButtonId();
RadioButton term = (RadioButton) findViewById(radioId);
mAuto.setLoanTerm(term.getText().toString());
}
答案1
得分: 2
使用String.valueOf();
mAuto.setLoanTerm(String.valueOf(term.getText()));
英文:
Use String.valueOf();
mAuto.setLoanTerm(String.valueOf(term.getText()));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论