2011年6月16日 星期四

2011/06/17 Android 期末另外50% 樂透抽獎+運算


===================================================================
Change.java
-------------------------------------------------
package edu.fcu.sean;

import android.app.Activity;
import android.content.res.ColorStateList;
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;
//EditText ed1, ed2;
private Button btn1;
private TextView tv1,tv2,tv6,tv7,tv8,tv9,tv10,tv11;
protected ColorStateList color;
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);    
        //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);
        tv2 = (TextView)Change.this.findViewById(R.id.textView5);
        tv6 = (TextView)Change.this.findViewById(R.id.textView6);
        tv7 = (TextView)Change.this.findViewById(R.id.textView7);
        tv8 = (TextView)Change.this.findViewById(R.id.textView8);
        tv9 = (TextView)Change.this.findViewById(R.id.textView9);
        tv10 = (TextView)Change.this.findViewById(R.id.textView10);
        tv11 = (TextView)Change.this.findViewById(R.id.textView11);
     
        //ed1.setText("50");
        //ed2.setText("100");
     
        btn1.setOnClickListener(new Button.OnClickListener()
        {
       
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ed1.setTextColor(Color.RED);
ed2.setTextColor(Color.BLUE);
tv6.setTextColor(Color.RED);
tv7.setTextColor(Color.GREEN);
tv8.setTextColor(Color.BLUE);
tv9.setTextColor(Color.YELLOW);
tv10.setTextColor(Color.WHITE);
tv11.setTextColor(Color.RED);
//tv1.setText(ed1.getText());
Double no1 = Double.valueOf(ed1.getText().toString());
Double no2 = Double.valueOf(ed2.getText().toString());

//String sum=String.format(String.valueOf(no2/no1), .2f);
String sum=String.valueOf(no1*no1);
String summ=String.valueOf((no2*no2)*no2);
//String sum=String.valueOf(no2/no1);,
//String.format(("{0:$#,0}", sum); // $3,456,234,532.0
 String z[]={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49"};
   // TODO Auto-generated method stub
       int ran;
          for (int i = 0; i < z.length; i++)
       {
           ran=(int)(Math.random()*48);
           String tmp=z[ran];
           z[ran]=z[i];
           z[i]=tmp;  
       }
          tv6.setText(""+z[1]);
          tv7.setText(""+z[2]);
          tv8.setText(""+z[3]);
          tv9.setText(""+z[4]);
          tv10.setText(""+z[5]);
          tv11.setText(""+z[6]);
       




//tv1.setText(sum);
tv1.setText(Change.this.getResources().getString(R.string.str4)+""+sum);
tv2.setText(Change.this.getResources().getString(R.string.str4)+""+summ);
tv6 = (TextView)Change.this.findViewById(R.id.textView6);
//String.Format("->{0,-10}<-", "Hello"); /*NumberFormat nf = NumberFormat.getInstance();
    /*nf.setMaximumFractionDigits( 2 );
     
    double d = Double.parseDouble(ed2.getText().toString()) / Double.parseDouble(ed1.getText().toString());
     
    tv1.setText( Change.this.getResources().getString(R.string.str4) + ":" + nf.format(d) );
*/

}





        });
     // 關閉程式的按鈕
Button button03 = (Button) findViewById(R.id.Button03);
button03.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
finish();
}
});
     
    }/*End: onCreate()*/
 

}
===================================================================
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:id="@+id/textView1" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:text="@string/str2">
    </TextView>
    
    <EditText 
    android:layout_height="wrap_content" 
    android:text="" 
    android:layout_width="fill_parent" 
    android:id="@+id/editText1">
    </EditText>
    <TextView android:id="@+id/textView3" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="@string/str_btn1">
    </TextView>
    <TextView android:id="@+id/textView2" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="@string/str3">
    </TextView>
    
    <EditText android:layout_height="wrap_content" 
    android:text="" 
    android:layout_width="fill_parent" 
    android:id="@+id/editText2"> 
    </EditText>
    <TextView android:id="@+id/textView5" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="@string/str_btn1">
    </TextView>
        <Button android:id="@+id/button1" 
    android:text="顯示答案" 
    android:layout_height="wrap_content" android:layout_width="fill_parent">
    </Button>
    <TextView android:text="樂透隨機亂數" 
    android:id="@+id/textView6" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="樂透隨機亂數" 
    android:id="@+id/textView7" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="樂透隨機亂數" 
    android:id="@+id/textView8" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="樂透隨機亂數" 
    android:id="@+id/textView9" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="樂透隨機亂數" 
    android:id="@+id/textView10" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="樂透隨機亂數" 
    android:id="@+id/textView11" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <TextView android:text="評價" 
    android:id="@+id/textView4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </TextView>
    <RatingBar android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:id="@+id/ratingBar1">
    </RatingBar>
    <Button android:text="退出程式" 
    android:id="@+id/Button03" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    </Button>
    




</LinearLayout>




===================================================================
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="str4">等於</string>
  <string name="str_btn1">顯示答案</string>
</resources>












===================================================================

沒有留言:

張貼留言

Use google protocol buffers + QT +CMAKE

Protocol Buffers https://developers.google.com/protocol-buffers/ Serialize and ParseFrom https://www.jianshu....