アンドロイドアプリを書く方法を自分自身で教えようとしていますが、ボタンクリックの登録に問題があり、その時点で選択されているラジオボタンに基づいて。これは簡単なヒント計算機です:Android - 登録ボタンラジオの選択に基づいて行動を起こす
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.RadioGroup;
import android.view.View;
public class TipCalc extends Activity implements RadioGroup.OnCheckedChangeListener,View.OnClickListener
{
TextView result;
RadioGroup radiogroup1;
RadioButton r1,r2,r3;
Button calculate;
EditText bill, resulttotal;
private int radioCheckedId = -1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
radiogroup1 = (RadioGroup) findViewById(R.id.radiogroup1);
Button calculate = (Button) findViewById(R.id.calculate);
RadioButton r1 = (RadioButton) findViewById(R.id.poor);
RadioButton r2 = (RadioButton) findViewById(R.id.average);
RadioButton r3 = (RadioButton) findViewById(R.id.excellent);
EditText bill = new EditText(this);
EditText resulttotal = new EditText(this);
radiogroup1.setOnCheckedChangeListener(this);
calculate.setOnClickListener(this);
//bill.setText("0");
//resulttotal.setText("0");
}
public void onCheckedChanged(RadioGroup group, int checkedId) {
radioCheckedId = checkedId;
}
public void onClick(View v)
{
if (v == calculate)
{
String billtotal;
double total = 0;
billtotal = bill.getText().toString();
final int aInt = Integer.parseInt(billtotal);
if (radioCheckedId == 1)
{
total = aInt * 1.1;
final String aString = Double.toString(total);
resulttotal.setText(aString);
}
if (radioCheckedId == 2)
{
total = aInt * 1.15;
final String aString = Double.toString(total);
resulttotal.setText(aString);
}
if (radioCheckedId == 3)
{
total = aInt * 1.2;
final String aString = Double.toString(total);
resulttotal.setText(aString);
}
}
}
}
すべてがロードされますが、仮想電話機の計算ボタンを押しても何も起こりません。
あなたはこれにそれを変更する意味ですか? EditText bill =(EditText)findViewById(R.id。ビル); EditText resulttotal =(EditText)findViewById(R.id.resulttotal); – MaQleod
それは問題ですが、問題ではありません**。 –
子供の代わりに現在のレイアウトに追加することで、どのような障害が発生しますか? – MaQleod