0
您好,我在adroid上有一個應用程序的以下代碼。Eclipse應用程序刪除按鈕並自動執行程序
在text3(et3)當我們按下按鈕時,它會在text3字段返回一個結果。它就像一個計算器。
我想刪除按鈕,所以程序一直工作,出來按它。
enter code here
package com.example.b15_calc;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
EditText et1, et2, et3, et4;
Button b1, b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1 = (EditText) findViewById(R.id.editText1);
et2 = (EditText) findViewById(R.id.editText2);
et3 = (EditText) findViewById(R.id.editText3);
et4 = (EditText) findViewById(R.id.editText4);
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
//step3 : write add functionality.
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
et1.setText("");
et2.setText("");
et3.setText("");
et4.setText("");
}
});
//step3 : ΜΕΤΑΒΛΗΤΕΣ
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String f = et1.getText().toString();
double i = Double.parseDouble(f);
String s = et2.getText().toString();
double j = Double.parseDouble(s);
String w = et4.getText().toString();
double q = Double.parseDouble(w);
double price_gold = 10;
double fpa = 1.23;
double fpol = 0.10;
double fpolam = 999;
double isot = 100;
double sint_ker = 10;
double result1 = (i * price_gold) + (j * 1000) + (q * isot);
double result2 = result1/340.75;
int gap;
if (result2 >= fpolam){
double result = (result2 * fpol);
double result3 = ((result2 * sint_ker) * fpa) + result;
if(result3 < 1000)
{
gap = 10;
}
else if(result3 < 5000)
{
gap = 50;
}
else //5000+
{
gap = 100;
}
int total = (int) Math.ceil(result3/gap) * gap;
String res = String.valueOf(total);
et3.setText(res);
} else{
double result3 = ((result2 * sint_ker) * fpa);
if(result3 < 1000)
{
gap = 10;
}
else if(result3 < 5000)
{
gap = 50;
}
else //5000+
{
gap = 100;
}
int total = (int) Math.ceil(result3/gap) * gap;
String res = String.valueOf(total);
et3.setText(res);
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
顯示你的代碼...... – 2014-12-09 14:18:00
我的代碼包含在我的消息中。不是嗎? – teok1979 2014-12-09 14:26:20
對不起。我現在改變它 – teok1979 2014-12-09 14:29:26