2011年5月27日 星期五

5/27 JAVA 作業

程式碼
package edu.fcu.d9790384;

import java.text.NumberFormat;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class change extends Activity {

private EditText ed1, ed2;
 private Button btn1;
 private TextView tv1;
 public static final String MY_PREFS = "mSharedPreferences01";



    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ed1 = (EditText)change.this.findViewById(R.id.editText1);  // 匯率
        ed2 = (EditText)change.this.findViewById(R.id.editText2);  // 台幣
        btn1 = (Button)change.this.findViewById(R.id.button1);
        tv1 = (TextView)change.this.findViewById(R.id.textView3);
       
        ed1.setText("33.5");
        ed2.setText("10000");
       
        btn1.setOnClickListener(new Button.OnClickListener()
        {
          @Override
          public void onClick(View arg0)
          {
            // 按鈕事件,處理數學換算的語法
         ed1.setText("99999"); //設定TextBox的數字
         ed2.setText("20000");
         tv1.setTextColor(Color.GREEN); //變換數字顏色
          }
        });
    }
}
================文字設定==================

<?xml version="1.0" encoding="utf-8"?>
<resources>
      <string name="hello">Hello World, EX203!</string>
  <string name="app_name">change</string>
 
  <string name="str1">匯率換算</string>
  <string name="str2">匯率</string>
  <string name="str3">臺幣</string>
 
  <string name="str_btn1">可兌換美金</string>
</resources>
================版面設定==================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="vertical">
    
    <TextView android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:text="@string/str1" 
    android:id="@+id/textView1">
    </TextView>
    
    <TextView android:text="@string/str2" 
    android:id="@+id/textView4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    
    <EditText android:text="" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:id="@+id/editText1">
    </EditText>
    
    <TextView android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:text="@string/str3" 
    android:id="@+id/textView2">
    </TextView>
    
    <EditText android:text="" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:id="@+id/editText2">
    </EditText>
    
    <Button android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:id="@+id/button1" 
    android:text="兌換美金">
    </Button>
    
    <TextView android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:text="@string/str_btn1" 
    android:id="@+id/textView3">
    </TextView>

</LinearLayout>

沒有留言:

張貼留言