http://www.oschina.net/question/999790_102938
一共3类 MainACtivity History Numbers
注意全局变量和局部变量的使用
package com.example.testdemo;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
Button btn, btnF;
Numbers ns = new Numbers();
TextView tvRed, tvBule;
File f = new File("/sdcard/History.txt");
Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.what == 100) {
tvRed.setText(ns.array[0] + " " + ns.array[1] + " "
+ ns.array[2] + " " + ns.array[3] + " " + ns.array[4]
+ " " + ns.array[5] + " ");
tvRed.setTextColor(Color.RED);
tvBule.setText("" + ns.array[6]);
tvBule.setTextColor(Color.BLUE);
}
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvRed = (TextView) findViewById(R.id.textRed);
tvBule = (TextView) findViewById(R.id.textBule);
btn = (Button) findViewById(R.id.buttonStart);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
ns.init(); //初始化一下
// for (int i = 0; i < ns.array.length; i++) {
// if (i != 6) {
// if (i > 1) {
// do {