2015-02-28 22:58:07| 分类: Android 开发每日 | 标签: |举报 |字号大中小 订阅
import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.TextView; /*from w ww.j av a 2 s .com*/ public class MainActivity extends Activity { TextView txtView1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); txtView1 = (TextView) findViewById(R.id.textView1); } public void startCounter(View view) { for (int i=0; i<=1000; i++) { txtView1.setText(String.valueOf(i)); try { Thread.sleep(1000); } catch (InterruptedException e) { Log.d("Threading", e.getLocalizedMessage()); } } } }
<?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_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/btnStartCounter" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Start" android:onClick="startCounter" /> <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="TextView" /> </LinearLayout>
评论