本帖最後由 洪振庭 於 2018-8-25 12:04 編輯
- package com.example.student.myapplication;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- EditText input;
- TextView text;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- input= (EditText) findViewById(R.id.input);
- text= (TextView) findViewById(R.id.result);
- }
- public void click(View view){
- int number=Integer.parseInt(input.getText().toString());
- double result=number*3.3058;
- text.setText("面積:"+String.valueOf(result)+"平方公尺");
- }
- public void clear(View view) {
- input.setText("");
- text.setText("");
- }
- }
複製代碼 |