我有 3 个复选框和 2 个编辑文本。当用户选中一个复选框并在一个编辑文本中输入数据时,就会发生计算。如果我选中另一个复选框,edittext 值应该会自动清除。然而,即使在我检查了其他复选框之后,edittexts 中的数据仍然存在。我尝试了关闭应用程序的完成()。知道如何在不关闭应用程序的情况下实现这一目标吗?
对不起,如果这个问题听起来很奇怪。我只是学习android 谢谢。
我的 onCheckedChangedListener 的代码
public void onCheckedChanged(CompoundButton predictionChkView, boolean isPredictionChecked)
{
// TODO Auto-generated method stub
switch(predictionChkView.getId())
{
case R.id.chkLastMileage1:
isChkLastMileage1=true;
chkLastMileage5.setChecked(false);
chkLastMileage10.setChecked(false);
ETPredictKm.setText("");
ETPredictFuelQty.setText("");
break;
case R.id.chkLastMileage5:
isChkLastMileage5=true;
chkLastMileage1.setChecked(false);
chkLastMileage10.setChecked(false);
ETPredictKm.setText("");
ETPredictFuelQty.setText("");
break;
case R.id.chkLastMileage10:
isChkLastMileage10 =true;
chkLastMileage1.setChecked(false);
chkLastMileage5.setChecked(false);
ETPredictKm.setText("");
ETPredictFuelQty.setText("");
break;
}
}
Code for the onFocusChangedListener
public void onFocusChange(View predictionFocusView, boolean hasPredictionETFocus)
{
// TODO Auto-generated method stub
FuelStoredInfo predictInfo = new FuelStoredInfo(this);
predictInfo.open();
predictInfo.getAvgMileage(this);
predictInfo.close();
try
{
predictKm = Long.parseLong(ETPredictKm.getText().toString());
predictFuetlQty = Double.parseDouble(ETPredictFuelQty.getText().toString());
}
catch(NumberFormatException ne)
{
ne.printStackTrace();
}
if(isChkLastMileage1 ==true || isChkLastMileage5==true||isChkLastMileage10==true)
{
if(ETPredictKm.hasFocus())
{
ETPredictKm.setText("");
if(predictFuetlQty!=0)
{
predictKm =(long) (predictionMileage*predictFuetlQty);
//setPredictKm(predictKm);
ETPredictKm.setText(String.valueOf(predictKm));
}
}
else if(ETPredictFuelQty.hasFocus())
{
ETPredictFuelQty.setText("");
if(predictKm!=0)
{
predictFuetlQty =predictKm/predictionMileage;
//setPredictFuetlQty(predictFuetlQty);
ETPredictFuelQty.setText(new DecimalFormat("##.##").format(predictFuetlQty));
}
}
}
else
{
Toast.makeText(getApplicationContext(), "Please check a checkbox!", Toast.LENGTH_LONG).show();
}
}
public void onClick(View v)
{
// TODO Auto-generated method stub
ETPredictKm.setText("");
ETPredictFuelQty.setText("");
chkLastMileage1.setChecked(false);
chkLastMileage5.setChecked(false);
chkLastMileage10.setChecked(false);
}