(1)利用button將textview的值進行運作,並以settext方式呈現出計算的值
package COM.TQC.GDD01; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class GDD01 extends Activity { public Button mButton1; public EditText mEditText1,mEditText2,mEditText3; public TextView mTextView1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mButton1=(Button)findViewById(R.id.submit); mEditText1=(EditText)findViewById(R.id.input_lend); mEditText2=(EditText)findViewById(R.id.input_rate); mEditText3=(EditText)findViewById(R.id.input_number); mTextView1=(TextView)findViewById(R.id.amount); mButton1.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { int a =Integer.parseInt(mEditText1.getText().toString()); Double b =Double.parseDouble(mEditText2.getText().toString()); int c =Integer.parseInt(mEditText3.getText().toString()); b=b/100/12+1; Double count=b; for(int i=1;i< c;i++) { count=count*b; } int area= (int) (a*count); String answer=Integer.toString(area); mTextView1.setText("本利和為"+answer); } }); } }
沒有留言:
張貼留言