私は簡単な計算機を作っています。-/ +ボタンには次のコードを書きます。
float ab=-1;
this.txtScreen = (EditText) findViewById(R.id.txtScreen);
unary=(Button)findViewById(R.id.plusminus);
mod=(Button)findViewById(R.id.modul);
unary.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtScreen.setText(ab*txtScreen);
}
});
エラーを表示*演算子はfloatに適用できません。
これを試してください(文字列が必要です):
float ab=-1;
unary=(Button)findViewById(R.id.plusminus);
mod=(Button)findViewById(R.id.modul);
unary.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtScreen.setText(String.valueOf(ab * Float.valueOf(txtScreen.getText().toString())));
}
});
編集:計算でtxtScreenから値を取得します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加