[android-developers] Re: question about handle and runnables
No, that isn't the problem. On 23 Feb, 09:24, Néstor Pavón Puro nespap...@yahoo.es wrote: Maybe because the second option is not to much time displayed? Put more time between the second and the third option. --- El mar, 23/2/10, Michael Lam mmingfei...@gmail.com escribió: De: Michael Lam mmingfei...@gmail.com Asunto: [android-developers] question about handle and runnables Para: Android Developers android-developers@googlegroups.com Fecha: martes, 23 de febrero, 2010 06:58 hi, i am using handle and runnables to switch/change the content of the TextView using a timer. for some reason, when running, the app always skips the second step (Step Two: fry egg), and only show the last (third) step (Step three: serve egg). TextView t; private String sText; private Handler mHandler = new Handler(); private Runnable mWaitRunnable = new Runnable() { public void run() { t.setText(sText); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mMonster = BitmapFactory.decodeResource(getResources(), R.drawable.monster1); t=new TextView(this); t=(TextView)findViewById(R.id.TextView01); sText = Step One: unpack egg; t.setText(sText); sText = Step Two: fry egg; mHandler.postDelayed(mWaitRunnable, 3000); sText = Step three: serve egg; mHandler.postDelayed(mWaitRunnable, 4000); ... } -- 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 athttp://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
[android-developers] Re: question about handle and runnables
Hi, I'm not seeing any code where you are creating a new handler to use You need a mHandler = new Handler(); in your OnCreate routine BEFORE you use it. -niko On Feb 23, 2:50 am, Kaj Bjurman kaj.bjur...@gmail.com wrote: No, that isn't the problem. On 23 Feb, 09:24, Néstor Pavón Puro nespap...@yahoo.es wrote: Maybe because the second option is not to much time displayed? Put more time between the second and the third option. --- El mar, 23/2/10, Michael Lam mmingfei...@gmail.com escribió: De: Michael Lam mmingfei...@gmail.com Asunto: [android-developers] question about handle and runnables Para: Android Developers android-developers@googlegroups.com Fecha: martes, 23 de febrero, 2010 06:58 hi, i am using handle and runnables to switch/change the content of the TextView using a timer. for some reason, when running, the app always skips the second step (Step Two: fry egg), and only show the last (third) step (Step three: serve egg). TextView t; private String sText; private Handler mHandler = new Handler(); private Runnable mWaitRunnable = new Runnable() { public void run() { t.setText(sText); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mMonster = BitmapFactory.decodeResource(getResources(), R.drawable.monster1); t=new TextView(this); t=(TextView)findViewById(R.id.TextView01); sText = Step One: unpack egg; t.setText(sText); sText = Step Two: fry egg; mHandler.postDelayed(mWaitRunnable, 3000); sText = Step three: serve egg; mHandler.postDelayed(mWaitRunnable, 4000); ... } -- 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 athttp://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
[android-developers] Re: question about handle and runnables
He created them where he declared them. On 23 Feb, 14:34, niko20 nikolatesl...@yahoo.com wrote: Hi, I'm not seeing any code where you are creating a new handler to use You need a mHandler = new Handler(); in your OnCreate routine BEFORE you use it. -niko On Feb 23, 2:50 am, Kaj Bjurman kaj.bjur...@gmail.com wrote: No, that isn't the problem. On 23 Feb, 09:24, Néstor Pavón Puro nespap...@yahoo.es wrote: Maybe because the second option is not to much time displayed? Put more time between the second and the third option. --- El mar, 23/2/10, Michael Lam mmingfei...@gmail.com escribió: De: Michael Lam mmingfei...@gmail.com Asunto: [android-developers] question about handle and runnables Para: Android Developers android-developers@googlegroups.com Fecha: martes, 23 de febrero, 2010 06:58 hi, i am using handle and runnables to switch/change the content of the TextView using a timer. for some reason, when running, the app always skips the second step (Step Two: fry egg), and only show the last (third) step (Step three: serve egg). TextView t; private String sText; private Handler mHandler = new Handler(); private Runnable mWaitRunnable = new Runnable() { public void run() { t.setText(sText); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mMonster = BitmapFactory.decodeResource(getResources(), R.drawable.monster1); t=new TextView(this); t=(TextView)findViewById(R.id.TextView01); sText = Step One: unpack egg; t.setText(sText); sText = Step Two: fry egg; mHandler.postDelayed(mWaitRunnable, 3000); sText = Step three: serve egg; mHandler.postDelayed(mWaitRunnable, 4000); ... } -- 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 athttp://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
[android-developers] Re: question about handle and runnables
A wild thought: I'm wondering if you pass the same == Runnable in to postDelayed() if the second call perhaps actually resets the earlier one to a new time? It's not documented to do that, but it would fit your observed behavior. Instead of mWaitRunnable, try passing new Runnable() { ...} instead, so it's a separate instance. Slightly less efficient; your way would be preferred. On Feb 22, 9:58 pm, Michael Lam mmingfei...@gmail.com wrote: hi, i am using handle and runnables to switch/change the content of the TextView using a timer. for some reason, when running, the app always skips the second step (Step Two: fry egg), and only show the last (third) step (Step three: serve egg). TextView t; private String sText; private Handler mHandler = new Handler(); private Runnable mWaitRunnable = new Runnable() { public void run() { t.setText(sText); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mMonster = BitmapFactory.decodeResource(getResources(), R.drawable.monster1); t=new TextView(this); t=(TextView)findViewById(R.id.TextView01); sText = Step One: unpack egg; t.setText(sText); sText = Step Two: fry egg; mHandler.postDelayed(mWaitRunnable, 3000); sText = Step three: serve egg; mHandler.postDelayed(mWaitRunnable, 4000); ... } -- 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
[android-developers] Re: question about handle and runnables
No, that's not it. I misread Kaj's comment -- he hit the nail on the head, and noticed about 1 second after I hit 'Send'... You need to capture each one separately, either in separate local variables, or as member variables in a Runnable subclass, or as constants in separate anonymous Runnable. On Feb 23, 2:20 pm, Bob Kerns r...@acm.org wrote: A wild thought: I'm wondering if you pass the same == Runnable in to postDelayed() if the second call perhaps actually resets the earlier one to a new time? It's not documented to do that, but it would fit your observed behavior. Instead of mWaitRunnable, try passing new Runnable() { ...} instead, so it's a separate instance. Slightly less efficient; your way would be preferred. On Feb 22, 9:58 pm, Michael Lam mmingfei...@gmail.com wrote: hi, i am using handle and runnables to switch/change the content of the TextView using a timer. for some reason, when running, the app always skips the second step (Step Two: fry egg), and only show the last (third) step (Step three: serve egg). TextView t; private String sText; private Handler mHandler = new Handler(); private Runnable mWaitRunnable = new Runnable() { public void run() { t.setText(sText); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mMonster = BitmapFactory.decodeResource(getResources(), R.drawable.monster1); t=new TextView(this); t=(TextView)findViewById(R.id.TextView01); sText = Step One: unpack egg; t.setText(sText); sText = Step Two: fry egg; mHandler.postDelayed(mWaitRunnable, 3000); sText = Step three: serve egg; mHandler.postDelayed(mWaitRunnable, 4000); ... } -- 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
[android-developers] Re: question about handle and runnables
That's because you change sText before it has been displayed, so the sText is Step three: serve egg when mWaitRunnable is executed after 3 seconds. On 23 Feb, 06:58, Michael Lam mmingfei...@gmail.com wrote: hi, i am using handle and runnables to switch/change the content of the TextView using a timer. for some reason, when running, the app always skips the second step (Step Two: fry egg), and only show the last (third) step (Step three: serve egg). TextView t; private String sText; private Handler mHandler = new Handler(); private Runnable mWaitRunnable = new Runnable() { public void run() { t.setText(sText); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mMonster = BitmapFactory.decodeResource(getResources(), R.drawable.monster1); t=new TextView(this); t=(TextView)findViewById(R.id.TextView01); sText = Step One: unpack egg; t.setText(sText); sText = Step Two: fry egg; mHandler.postDelayed(mWaitRunnable, 3000); sText = Step three: serve egg; mHandler.postDelayed(mWaitRunnable, 4000); ... } -- 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