gpt4 book ai didi

java - 安卓|单选按钮不会做任何事情并保持按下状态

转载 作者:行者123 更新时间:2023-11-30 03:52:23 26 4
gpt4 key购买 nike

我正在尝试做一个货币转换器作业(我是编程新手)

除了单选按钮一直被按下并且什么都不做之外,一切都完成了(不将文本放入 TextView 并且单选按钮锁定在“按下”模式

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 rGroup, int checkedId)
{

switch (mRadioGroup.getCheckedRadioButtonId())
{
case R.id.dollar:
Double dollarConvert = Double.valueOf(mToConvert.getText().toString()); //convert the string to int
double price = dollarConvert * 1.28;
mDollar.setChecked(true);
Meuro.setChecked(false);
String result = mToConvert.getText().toString();
mResult.setText(result + price);
break;

case R.id.euro:
Double euroConvert = Double.valueOf(mToConvert.getText().toString()); //convert the string to int
double value = euroConvert * 1.28;
mDollar.setChecked(false);
Meuro.setChecked(true);
String result1 = mToConvert.getText().toString();
mResult.setText(result1 + value);
break;

default:;
}
}
});


}

最佳答案

你需要设置RadioGroup.setoncheckedchangelistener让 RadioGroup 在检查更改事件触发时执行一些操作。

mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup rGroup, int checkedId)
{
//do your code here
}
});

关于java - 安卓|单选按钮不会做任何事情并保持按下状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13936020/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com