package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
protected int splashTime = 1000;
TextView tv1, tvTimeInMinute;
int timer = 0;
Integer timeCounter = 0;
public static Integer minuteCounter = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.tvTimeCounter);
tvTimeInMinute = (TextView) findViewById(R.id.tvTimeInMinute);
Thread th = new Thread() {
@Override
public void run() {
try {
while (true) {
int secondStart = 0;
for (int i = secondStart; i < 5; i++) {
final Integer j = i;
Thread.sleep(1000);
runOnUiThread(new Runnable() {
public void run() {
try {
timeCounter++;
if (j == 4) {
Log.d("--if(timeCounter == 4)---minuteCounter="
+ minuteCounter.toString()
+ "------", " ");
minuteCounter++;
tvTimeInMinute
.setText(minuteCounter
.toString());
}
tv1.setText(j.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
} catch (InterruptedException e) {
}
}
};
th.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
}
activity_main.xml
------------------------------
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id = "@+id/tvTimeCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text=""
tools:context=".MainActivity" />
<TextView
android:id="@+id/tvTimeInMinute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/tvTimeCounter"
android:layout_alignBottom="@+id/tvTimeCounter"
android:layout_marginRight="16dp"
android:layout_toLeftOf="@+id/tvTimeCounter"
android:text="00"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
download: http://www.mediafire.com/?kinu8vnoabnh2c4
No comments:
Post a Comment