2011-05-27

2011/05/27

Android

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="hello">Hello World, EX203!</string>
  <string name="app_name">匯率換算</string>
 
  <string name="str1">匯率換算</string>
  <string name="str2">匯率</string>
  <string name="str3">臺幣</string>
 
  <string name="str_btn1">可兌換美金</string>
</resources>




main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <TextView
    android:text="@string/str2"
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    </TextView>
      
    <EditText
     android:layout_height="wrap_content"
     android:id="@+id/editText1"
     android:text=""
     android:layout_width="match_parent">
     </EditText>
    
    <TextView
    android:text="@string/str3"
    android:layout_height="wrap_content"
    android:id="@+id/textView2"
    android:layout_width="wrap_content">
    </TextView>
   
    <EditText
    android:layout_height="wrap_content"
    android:id="@+id/editText2"
    android:text=""
    android:layout_width="match_parent">
    </EditText>
   
    <Button
    android:text="計算台幣兌換美金"
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    </Button>
   
    <TextView
    android:text="@string/str_btn1"
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    </TextView>
   
</LinearLayout>



Try3.java

package Try.T;

import java.text.NumberFormat;

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 Try3 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)Try3.this.findViewById(R.id.editText1);  // 匯率
      ed2 = (EditText)Try3.this.findViewById(R.id.editText2);  // 台幣
      btn1 = (Button)Try3.this.findViewById(R.id.button1);
      tv1 = (TextView)Try3.this.findViewById(R.id.textView3);
       
     
      ed1.setText("33.5");
      ed2.setText("10000");
     
     
     
      btn1.setOnClickListener(new Button.OnClickListener()
      {
     
        public void onClick(View arg0)
        {
          btn1.setWidth(70);
           
           
            // 按鈕事件,處理數學換算的語法
          //NumberFormat nf = NumberFormat.getInstance();
          //nf.setMaximumFractionDigits( 2 );
         
          //double d = Double.parseDouble(ed2.getText().toString()) / Double.parseDouble(ed1.getText().toString());
         
          //tv1.setText( Try3.this.getResources().getString(R.string.str3) + ":" + nf.format(d) );
       
        }
      });
     
     
     
    }
}

沒有留言:

張貼留言