Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: Android
Hey, everyone.
I'm trying to make a basic tycoon game for Android
and I'm trying to increment the value of text-views every 5 seconds with a timer,
But the textview doesn't update.
Here's my code so far:
public class Town extends Activity implements OnClickListener {
	Timer timer;
	TimerTask task;
	TextView goldTV;
	TextView woodTV;
	TextView foodTV;
	TextView stoneTV;
	TextView cashTV;
	int gold = 20;
	int wood = 20;
	int food = 20;
	int stone = 20;
	int cash = 200;
	protected void onCreate(Bundle savedInstanceState) {
		goldTV = (TextView) findViewById(;
		woodTV = (TextView) findViewById(;
		foodTV = (TextView) findViewById(;
		stoneTV = (TextView) findViewById(;
		cashTV = (TextView) findViewById(;
		timer = new Timer();
		task = new TimerTask() {
			public void run() {
				try {
				catch (InterruptedException e){
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
Posted 27-Nov-12 12:00pm
(unknown member)
AndroidVivek at 8-Dec-12 2:12am
use handler , thread is good but for android handler is best
and if you are making more process in background then use asynch task

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,805
1 OriginalGriff 6,696
2 CPallini 5,350
3 George Jonsson 3,609
4 Gihan Liyanage 2,792

Advertise | Privacy | Mobile
Web04 | 2.8.140922.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100