標題:
土地面積換算
[打印本頁]
作者:
周政輝
時間:
2018-8-25 10:50
標題:
土地面積換算
使用 View.OnClickListener 介面實作一傾聽者物件,藉由覆寫 onClick() 方法定義點擊後所要執行的動作,並以 setOnClickListener() 方法為元件加上傾聽者,完成如下之練習:
[attach]4692[/attach]
作者:
黃茂勛
時間:
2018-8-25 11:47
本帖最後由 黃茂勛 於 2018-8-25 11:49 編輯
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 result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input = (EditText) findViewById(R.id.input);
result = (TextView) findViewById(R.id.result);
}
public void click(View view) {
Log.d("Einsteinlog", "welcome");
int num = Integer.parseInt(input.getText().toString());
double rs = num*3.3058;
result.setText("面積為: "+String.valueOf(rs)+"平方公尺");
}
public void clean(View view) {
Log.i("Albertlog","hello");
input.setText("");
result.setText("");
}
}
複製代碼
作者:
陳思惟
時間:
2018-8-25 12:00
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText in;
TextView t;
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
in=(EditText)findViewById(R.id.in);
t=(TextView)findViewById(R.id.t);
b1= (Button) findViewById(R.id.b1);
b2= (Button) findViewById(R.id.b2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a();
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
in.setText("");
t.setText("");
}
});
}
public void a()
{
int num=Integer.parseInt(in.getText().toString());
double re=num*3.3058;
t.setText("面積為:"+re+"平方公尺");
}
}
複製代碼
作者:
洪振庭
時間:
2018-8-25 12:01
本帖最後由 洪振庭 於 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("");
}
}
複製代碼
作者:
蔡庭豪
時間:
2018-8-25 12:03
public class MainActivity extends AppCompatActivity {
TextView tv;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = (EditText)findViewById(R.id.et);
tv = (TextView)findViewById(R.id.textView4);
}
public void deletefun(View view) {
Log.d("delete","clear");
tv.setText("");
et.setText("");
}
public void changefun(View view) {
Log.d("change","finish");
int input = Integer.parseInt(et.getText().toString());
double res = input*3.3058;
tv.setText(String.valueOf(res));
}
}
[code]
複製代碼
[/code]
作者:
蔡季樺
時間:
2018-8-27 20:40
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
EditText et ;
TextView tv;
Button btn,btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = (EditText)findViewById(R.id.editText);
tv = (TextView)findViewById(R.id.textView3);
btn = (Button) findViewById(R.id.button);
btn2 = (Button) findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
et.setText("");
tv.setText("");
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double a =Double.parseDouble(et.getText()+"");
String str = String.valueOf(a*3.3058);
tv.setText("面積為:"+str+"平方公尺");
}
});
}
}
複製代碼
作者:
黃璽安
時間:
2018-8-28 15:51
package com.example.shain.ch01;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class Ch01 extends AppCompatActivity {
EditText input;
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ch01);
input= (EditText) findViewById(R.id.editText);
text= (TextView) findViewById(R.id.textView3);
}
public void click(View view){
int number=Integer.parseInt(input.getText().toString());
double textView3=number*3.3058;
text.setText("面積:" + String.valueOf(textView3)+"平方公尺");
}
public void clear(View view) {
input.setText("");
text.setText("");
}
}
複製代碼
作者:
陳泓瑜
時間:
2018-9-19 20:42
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView tx1;
EditText et1;
Button bt1, bt2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tx1 = (TextView) findViewById(R.id.textView3);
et1 = (EditText) findViewById(R.id.editText);
bt1 = (Button) findViewById(R.id.button);
bt2 = (Button) findViewById(R.id.button2);
bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
et1.setText("");
tx1.setText("");
}
});
bt2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double res;
res = Double.parseDouble(et1.getText().toString())*3.3058;
tx1.setText("面積為: "+res+" m^2");
}
});
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2