Android Forums

Go Back   These FORUMS ARE DISABLED!! OUR NEW FORUMS ARE AT http://androidforum.com/ > Android Coders > Android Development, Answers, Tutorials, and Code Snippets
Connect with Facebook

Click Here To Register!
 
 
LinkBack Thread Tools Display Modes
Old 07-17-2010, 08:23 AM   #1
New Member
 
Join Date: Jul 2010
Posts: 1
Friends: 0
View brocke21's Profile   View brocke21's Photo Album   View brocke21's Blog   View Social Groups
Hello.
My name is Jarek and I've started to programm some stuff in the Android version of Java. Currently I was developing my applications in J2ME and now I'm trying to convert them to work on Android devices to use it's great features. So I've started to get familiar with the code and got stuck on a problem.

I'm trying to make a simple counter upwards to infinity when pressing a button. The loop works great in LogCat but somehow the TextView is never updated. When I remove the Thread.sleep() and use it to manually add 1 to "i" it works ok, just when trying to automate it something is not working.

Here is the java code :

Code:
package prog.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class startowe extends Activity
{
	
public int i;
public static TextView tabelka;
   public void onCreate(Bundle icicle)
   {
	   
      super.onCreate(icicle);
      setContentView(R.layout.startowe);
      tabelka = (TextView) findViewById(R.id.wys2);
      Button b = (Button) findViewById(R.id.btnClick);
      b.setOnClickListener(new View.OnClickListener() {
         public void onClick(View arg0) {
        
      	  try {
			startowe.this.wpisz();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		        
         }
      });
   }
   public void wpisz() throws Exception{
	   i = i+1;
	   System.out.println(""+i);
	   tabelka.setText(""+i);
	   Thread.sleep(5500);
	   startowe.this.wpisz();
	   }
   
}
And here is the XML layout file :

Code:
<?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/wys"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="You are in the first Screen"
/>
<Button
   android:id ="@+id/btnClick"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Open New Screen"
/>
<TextView
android:id="@+id/wys2"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text=""
/>

</LinearLayout>
Any help is welcome. Thank You
brocke21 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
 

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Samsung Galaxy S GT-I9000 - Apps stuck @ Starting download forever karunadheera Galaxy S (Captivate, Epic 4G, Fascinate & Vibrant) 6 08-09-2011 11:30 PM
Music player starting every time my EVO connects with SYNC via bluetooth in my truck FNED Android Chat 1 07-07-2010 07:25 AM
Randon apps starting randomly! homerjayk Android Chat 0 03-29-2010 03:31 PM
Stopping Apps from self-starting? jenqduck Droid 0 11-10-2009 09:10 AM
G1 preorders shipping starting tomorrow! Tiajunia Android Chat 15 10-18-2008 06:37 PM


Unlocked G1 Phones | Buy T-Mobile G1 | Google Phone

All times are GMT -6. The time now is 05:21 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2012 TalkAndroid.com. All rights reserved.