Re: [android-developers] Blinking Images

2011-01-16 Thread Felix long
在 2011年1月15日星期六,Kostya Vasilyev  写道:
> Braco,
>
> You are using a Java Timer, which invokes your TimerTask on a background 
> thread.
> In Android, only the original (UI) thread is allowed to touch the UI. 
> Touching the UI from a background thread, like your code does, produces 
> unpredictable results (possibly a crash).
>
> This should help you refactor you code:
> http://developer.android.com/resources/articles/timed-ui-updates.html
>
> -- Kostya
> 2011/1/13 braco_ 
>
> Hello,
>
> I have 4 Images
> final ImageView redImage = (ImageView) findViewById
> (R.id.circle_red);
> final ImageView blueImage = (ImageView) findViewById
> (R.id.circle_blue);
> final ImageView greenImage = (ImageView) findViewById
> (R.id.circle_green);
> final ImageView yellowImage = (ImageView) findViewById
> (R.id.circle_yellow);
>
> I try to blinking this images with a timer
> final Timer timer = new Timer();
>
> startButton.setOnClickListener(new View.OnClickListener() {
> @Override
> public void onClick(View v) {
> // TODO Auto-generated method stub
>
>
> timer.schedule(new 
> TaskTimer(yellowImage,punkteStand), 0, 2000);
> }
> });
>
> TaskTimer.java
> public TaskTimer(ImageView object, TextView pkt){
> image =  object;
> punkteStand = pkt;
> }
>
>
> @Override
> public void run() {
> // TODO Auto-generated method stub
> String istString = (new Integer(time)).toString();
> CharSequence abc = istString;
> punkteStand.setText(abc);
> time++;
> if(image.getVisibility() == View.INVISIBLE){
> image.setVisibility(View.VISIBLE);
> }
> else {
> image.setVisibility(View.INVISIBLE);
>
> }
>
> But if i start nothing happens how can i do that better that a image
> will blinking?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
Best Regards

Felix Long

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Blinking Images

2011-01-15 Thread Kostya Vasilyev
Braco,

You are using a Java Timer, which invokes your TimerTask on a background
thread.

In Android, only the original (UI) thread is allowed to touch the UI.
Touching the UI from a background thread, like your code does, produces
unpredictable results (possibly a crash).

This should help you refactor you code:

http://developer.android.com/resources/articles/timed-ui-updates.html

-- Kostya

2011/1/13 braco_ 

> Hello,
>
> I have 4 Images
>final ImageView redImage = (ImageView) findViewById
> (R.id.circle_red);
>final ImageView blueImage = (ImageView) findViewById
> (R.id.circle_blue);
>final ImageView greenImage = (ImageView) findViewById
> (R.id.circle_green);
>final ImageView yellowImage = (ImageView) findViewById
> (R.id.circle_yellow);
>
> I try to blinking this images with a timer
> final Timer timer = new Timer();
>
> startButton.setOnClickListener(new View.OnClickListener() {
>@Override
>public void onClick(View v) {
>// TODO Auto-generated method stub
>
>
>timer.schedule(new
> TaskTimer(yellowImage,punkteStand), 0, 2000);
>}
> });
>
> TaskTimer.java
> public TaskTimer(ImageView object, TextView pkt){
>image =  object;
>punkteStand = pkt;
>}
>
>
>@Override
>public void run() {
>// TODO Auto-generated method stub
>String istString = (new Integer(time)).toString();
>CharSequence abc = istString;
>punkteStand.setText(abc);
>time++;
>if(image.getVisibility() == View.INVISIBLE){
>image.setVisibility(View.VISIBLE);
>}
>else {
>image.setVisibility(View.INVISIBLE);
>
>}
>
> But if i start nothing happens how can i do that better that a image
> will blinking?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Blinking Images

2011-01-14 Thread TreKing
On Thu, Jan 13, 2011 at 6:51 AM, braco_  wrote:

> But if i start nothing happens how can i do that better that a image will
> blinking?
>

Use. Your. Debugger.

-
TreKing  - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Blinking Images

2011-01-14 Thread Kumar Bibek
Is your run method being executed?

Kumar Bibek
http://techdroid.kbeanie.com
http://www.kbeanie.com



On Thu, Jan 13, 2011 at 6:21 PM, braco_  wrote:

> Hello,
>
> I have 4 Images
>final ImageView redImage = (ImageView) findViewById
> (R.id.circle_red);
>final ImageView blueImage = (ImageView) findViewById
> (R.id.circle_blue);
>final ImageView greenImage = (ImageView) findViewById
> (R.id.circle_green);
>final ImageView yellowImage = (ImageView) findViewById
> (R.id.circle_yellow);
>
> I try to blinking this images with a timer
> final Timer timer = new Timer();
>
> startButton.setOnClickListener(new View.OnClickListener() {
>@Override
>public void onClick(View v) {
>// TODO Auto-generated method stub
>
>
>timer.schedule(new
> TaskTimer(yellowImage,punkteStand), 0, 2000);
>}
> });
>
> TaskTimer.java
> public TaskTimer(ImageView object, TextView pkt){
>image =  object;
>punkteStand = pkt;
>}
>
>
>@Override
>public void run() {
>// TODO Auto-generated method stub
>String istString = (new Integer(time)).toString();
>CharSequence abc = istString;
>punkteStand.setText(abc);
>time++;
>if(image.getVisibility() == View.INVISIBLE){
>image.setVisibility(View.VISIBLE);
>}
>else {
>image.setVisibility(View.INVISIBLE);
>
>}
>
> But if i start nothing happens how can i do that better that a image
> will blinking?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en