EditTextからさまざまな方法で値を取得できますが、操作を行う場合は、最初にこれらのことを確認してください。EditTextのXMLのレイアウトで、android:inputType
がに設定されていることを確認してください。そうしないと"number"
、ユーザーがアプリを台無しにしないようになります。"numberSigned"
"numberDecimal"
次に、Javaクラスで、期待される出力に応じて、数値の引数をグローバルに0に初期化します。整数(int)は整数(inputType numberまたはnumberSigned)の間の合計または減算、またはより一般的にはすべての操作のdoubleです。
最後に、情報を解析する必要があります。2つの不要な変換が含まれるため、テキスト文字列として取得するのではありません。
public void wattSystemView(View view) {
/**
* decimal values entered in hor_editText and wh_editText
* number of days without sun of the system as a whole number at days_editText
*/
hours = (EditText) findViewById(R.id.hor_editText);
wh = (EditText) findViewById(R.id.wh_editText);
daysNoSun = (EditText) findViewById(R.id.nosun_days_editText);
/**
* conversion to double of the decimal values entered
* conversion to integer of the number of days without sun of the system
*/
numh = Double.parseDouble(hours.getText().toString());
numwh = Double.parseDouble(wh.getText().toString());
nosundays = Integer.parseInt(daysNoSun.getText().toString());
/**
* simple math
*/
double wattDay = numh * numwh;
double wattSys = wattDay*nosundays;