我正在尝试将添加文本更改侦听器添加到我的代码中,因此当我编辑文本时,它会自动将货币转换为选定的单选按钮(美元、欧元),而无需按下其中一个单选按钮使其显示在文本视图中回答。
我不知道该怎么做我是新的编程在谷歌搜索没有找到答案
package com.gardana.superh;
public class ConvertActivity extends Activity {
TextView mResult;
EditText mToConvert;
RadioGroup mRadioGroup;
RadioButton mDollar, Meuro;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_convert);
mResult = (TextView) findViewById(R.id.result);
mToConvert = (EditText) findViewById(R.id.toConvert);
mRadioGroup = (RadioGroup) findViewById(R.id.radioG);
mDollar = (RadioButton) findViewById(R.id.dollar);
Meuro = (RadioButton) findViewById(R.id.euro);
mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup mradRadioGroup, int checkedId)
{
switch (checkedId)
{
case R.id.dollar:
Double dollarConvert = Double.valueOf(mToConvert.getText().toString()); //convert the string to int
double price = dollarConvert * 3.76;
mDollar.setChecked(true);
Meuro.setChecked(false);
mResult.setText("$"+price);
break;
case R.id.euro:
Double euroConvert = Double.valueOf(mToConvert.getText().toString()); //convert the string to int
double value = euroConvert * 5;
mDollar.setChecked(false);
Meuro.setChecked(true);
mResult.setText("€" + value);
Meuro.setChecked(false);
break;
default:;
}
}
});
}
}