TQC-202 英呎 、 公尺互轉
這是TQC的202題,
程式碼為自行撰寫,
僅供參考。
主要練習轉型
package COM.TQC.GDD02;
/*
題目說明:
英呎 = 公尺 * 3.28
公尺 = 英呎 * 0.3048
*/
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class GDD02 extends Activity {
protected String PREF_M = "pref_m";
protected String PREF_FT = "pref_ft";
protected String pref_m;
protected String pref_ft;
private Button Button1,Button2;
private EditText EText;
private TextView infoView;
double _Con1,_Con2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findview();
setlistener();
}
public void findview()
{
EText = (EditText) findViewById(R.id.editText1);
infoView = (TextView)findViewById(R.id.textView2);
Button1= (Button)findViewById(R.id.button1);
Button2= (Button)findViewById(R.id.button2);
}
public void setlistener()
{
Button1.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Convert1();
}
});
Button2.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Convert2();
}
});
}
private void Convert1()
{
_Con1=Double.parseDouble(EText.getText().toString())*3.28;
infoView.setText(String.valueOf(_Con1));
}
private void Convert2()
{
_Con2=Double.parseDouble(EText.getText().toString())*0.3048;
infoView.setText(String.valueOf(_Con2));
}
protected static final int MENU_RESET =Menu.FIRST;
@Override
public boolean
onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
menu.add(0, MENU_RESET, 0, "ResetValue...");
return true;
}
public boolean
onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId()){
case MENU_RESET:
ResetValue();
break;
}
return true;
}
private void ResetValue()
{
EText.setText("");
infoView.setText("");
}
}
自我LV~