0
私の結果を保持する "results"という名前のテキストエリアがあります。 XMLからテキストエリアの不要な10進数
デフォルトは次のとおりです。 "0"
計算した後、以下に示すクラスファイルから、すなわち返す: "1.0"
私は望んでいません ""または「0」だけで全体の数字、つまり「1」「2」「3」等...私はintとしてテキスト領域から値を取得するには、これを修正しようとしてい
protected void addone() {
double val = Double.parseDouble(results.getText().toString());
results.setText(Double.toString(val+1));
}
protected void minusone() {
double val = Double.parseDouble(results.getText().toString());
if (val > 0){
results.setText(Double.toString(val-1));
}
}
protected void resetit() {
AlertDialog.Builder ab=new AlertDialog.Builder(actcountonit.this);
ab.setMessage(Html.fromHtml("<b><font color=#ff0000> Warning.! " +"</font></b><br>Are you sure you want to reset the counter..?"));
ab.setPositiveButton("Reset", new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
results.setText(Double.toString(0));
}
});
ab.setNegativeButton("Cancel", null);
ab.show();
}
、その後復帰intとしてのテキスト領域に変換します。 私が試したすべての組み合わせ、私はこれらの行にエラーが発生します。
protected void addone() {
double val = Double.parseDouble(results.getText().toString());
results.setText(Double.toString(val+1));
}
あなたはintとして、テキストボックスの数値を取って、このような関数の例は、CALCSはその後、int型「整数」としてそれを返すかは、素晴らしいことです...!
この修正案は、大文字の "Int"と "
protected void addone() {
int val = Int.parseInt(results.getText().toString());
results.setText(Int.toString(val+1));
}
は、最後にそれを働いた:
protected void addone() {
int val = Integer.parseInt(results.getText().toString());
results.setText(Integer.toString(val+1));
}
私はeclipseでこれらのonclickイベントを構築するさまざまな方法を試しました。しかし、私はアンドロイドとJavaに新しいので、私は正しいフォーマットを取得することはできません。 –
'Double'の代わりに' int'を使ってみてください。何らかの小数点の計算をしていない限り、ここでダブルを使用する理由はありません。 – kcoppock
私は試してみましたが、私は文法にまだ十分な能力がありません。私は元の投稿の一番下にメモを修正しました。 –