[android-developers] Re: Replace the current view by an other view

2009-01-21 Thread for android
you are probably calling from a seperate thread..after thread has done its
wrk...use the handler and change the view..

On Wed, Jan 21, 2009 at 7:49 PM, Nico nicolas.d...@gmail.com wrote:


 Hi,
 I need to replace the current View (set by the activity.setContentView
 method) by an other.
 When I call activity.setContentView two times, I get this exception :
 01-21 14:13:54.747: WARN/System.err(1156): android.view.ViewRoot
 $CalledFromWrongThreadException: Only the original thread that created
 a view hierarchy can touch its views.
 01-21 14:13:54.757: WARN/System.err(1156): at
 android.view.ViewRoot.checkThread(ViewRoot.java:1849)
 01-21 14:13:54.757: WARN/System.err(1156): at
 android.view.ViewRoot.requestLayout(ViewRoot.java:455)
 01-21 14:13:54.767: WARN/System.err(1156): at
 android.view.View.requestLayout(View.java:6575)
 01-21 14:13:54.767: WARN/System.err(1156): at
 android.view.View.requestLayout(View.java:6575)
 01-21 14:13:54.777: WARN/System.err(1156): at
 android.view.View.requestLayout(View.java:6575)
 01-21 14:13:54.777: WARN/System.err(1156): at
 android.view.ViewGroup.removeAllViews(ViewGroup.java:2033)
 What is problem ?
 Thx
 


--~--~-~--~~~---~--~~
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: Replace the current view by an other view

2009-01-21 Thread for android
i have one question around the runOnUiThread...Basically when i used this
method in the onCreate/onStart of the Activity,i found that it works quite
differently than i expect..

For example in the onCreate/onStart..say I have long running operation
before which i want to render the UI with a progress bar.and after the long
runnin operation is complete remove the progress bar and show the view..In
this case I found that the UI is rendered only after the long running
operation...so i end up not seeing the progress bar..I ended up using the
handler...Am i going wrong in my understanding of this method?



protected void onStart(){
super.onStart();
Progress Bar Visible
runOnUiThread( new Thread() {
// go get our feed!
public void run() {
//longrunning operation
 //Progress Bar Gone
 //show the required view

}
});
}

On Wed, Jan 21, 2009 at 7:55 PM, Mark Murphy mmur...@commonsware.comwrote:


 Nico wrote:
  Hi,
  I need to replace the current View (set by the activity.setContentView
  method) by an other.
  When I call activity.setContentView two times, I get this exception :
  01-21 14:13:54.747: WARN/System.err(1156): android.view.ViewRoot
  $CalledFromWrongThreadException: Only the original thread that created
  a view hierarchy can touch its views.
  01-21 14:13:54.757: WARN/System.err(1156): at
  android.view.ViewRoot.checkThread(ViewRoot.java:1849)
  01-21 14:13:54.757: WARN/System.err(1156): at
  android.view.ViewRoot.requestLayout(ViewRoot.java:455)
  01-21 14:13:54.767: WARN/System.err(1156): at
  android.view.View.requestLayout(View.java:6575)
  01-21 14:13:54.767: WARN/System.err(1156): at
  android.view.View.requestLayout(View.java:6575)
  01-21 14:13:54.777: WARN/System.err(1156): at
  android.view.View.requestLayout(View.java:6575)
  01-21 14:13:54.777: WARN/System.err(1156): at
  android.view.ViewGroup.removeAllViews(ViewGroup.java:2033)
  What is problem ?

 As the exception says: Only the original thread that created
 a view hierarchy can touch its views.

 Are you attempting to call setContentView() from a background thread? If
 so, arrange to call it on the UI thread, via post(), runOnUiThread(), or
 a Handler.

 --
 Mark Murphy (a Commons Guy)
 http://commonsware.com
 Android Training in Sweden -- http://www.sotrium.com/training.php

 


--~--~-~--~~~---~--~~
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: Replace the current view by an other view

2009-01-21 Thread Nico

I did it :

// Create a thread to change the view
final Grid f_grid = grid;
Runnable mainThreadRunnable = new Runnable() {
public void run() {
m_activity.setContentView(f_grid);
}
};
// Run the thread
m_activity.runOnUiThread(mainThreadRunnable);

It works great, is it a correct way ?

On 21 jan, 15:23, for android forandr...@gmail.com wrote:
 you are probably calling from a seperate thread..after thread has done its
 wrk...use the handler and change the view..

 On Wed, Jan 21, 2009 at 7:49 PM, Nico nicolas.d...@gmail.com wrote:

  Hi,
  I need to replace the current View (set by the activity.setContentView
  method) by an other.
  When I call activity.setContentView two times, I get this exception :
  01-21 14:13:54.747: WARN/System.err(1156): android.view.ViewRoot
  $CalledFromWrongThreadException: Only the original thread that created
  a view hierarchy can touch its views.
  01-21 14:13:54.757: WARN/System.err(1156):     at
  android.view.ViewRoot.checkThread(ViewRoot.java:1849)
  01-21 14:13:54.757: WARN/System.err(1156):     at
  android.view.ViewRoot.requestLayout(ViewRoot.java:455)
  01-21 14:13:54.767: WARN/System.err(1156):     at
  android.view.View.requestLayout(View.java:6575)
  01-21 14:13:54.767: WARN/System.err(1156):     at
  android.view.View.requestLayout(View.java:6575)
  01-21 14:13:54.777: WARN/System.err(1156):     at
  android.view.View.requestLayout(View.java:6575)
  01-21 14:13:54.777: WARN/System.err(1156):     at
  android.view.ViewGroup.removeAllViews(ViewGroup.java:2033)
  What is problem ?
  Thx
--~--~-~--~~~---~--~~
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: Replace the current view by an other view

2009-01-21 Thread Nico

Thx a lot for help.

On 21 jan, 16:02, Mark Murphy mmur...@commonsware.com wrote:
 Nico wrote:
  I did it :

             // Create a thread to change the view
             final Grid f_grid = grid;
             Runnable mainThreadRunnable = new Runnable() {
                     public void run() {
                             m_activity.setContentView(f_grid);
                     }
          };
          // Run the thread
             m_activity.runOnUiThread(mainThreadRunnable);

 That should work fine, AFAIK.

 --
 Mark Murphy (a Commons Guy)http://commonsware.com
 Android Training in Sweden --http://www.sotrium.com/training.php
--~--~-~--~~~---~--~~
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: Replace the current view by an other view

2009-01-21 Thread for android
any help on this ??

On Wed, Jan 21, 2009 at 8:13 PM, for android forandr...@gmail.com wrote:

 i have one question around the runOnUiThread...Basically when i used this
 method in the onCreate/onStart of the Activity,i found that it works quite
 differently than i expect..

 For example in the onCreate/onStart..say I have long running operation
 before which i want to render the UI with a progress bar.and after the long
 runnin operation is complete remove the progress bar and show the view..In
 this case I found that the UI is rendered only after the long running
 operation...so i end up not seeing the progress bar..I ended up using the
 handler...Am i going wrong in my understanding of this method?



 protected void onStart(){
 super.onStart();
 Progress Bar Visible
 runOnUiThread( new Thread() {
 // go get our feed!
 public void run() {
 //longrunning operation
  //Progress Bar Gone
  //show the required view

 }
 });

 }

 On Wed, Jan 21, 2009 at 7:55 PM, Mark Murphy mmur...@commonsware.comwrote:


 Nico wrote:
  Hi,
  I need to replace the current View (set by the activity.setContentView
  method) by an other.
  When I call activity.setContentView two times, I get this exception :
  01-21 14:13:54.747: WARN/System.err(1156): android.view.ViewRoot
  $CalledFromWrongThreadException: Only the original thread that created
  a view hierarchy can touch its views.
  01-21 14:13:54.757: WARN/System.err(1156): at
  android.view.ViewRoot.checkThread(ViewRoot.java:1849)
  01-21 14:13:54.757: WARN/System.err(1156): at
  android.view.ViewRoot.requestLayout(ViewRoot.java:455)
  01-21 14:13:54.767: WARN/System.err(1156): at
  android.view.View.requestLayout(View.java:6575)
  01-21 14:13:54.767: WARN/System.err(1156): at
  android.view.View.requestLayout(View.java:6575)
  01-21 14:13:54.777: WARN/System.err(1156): at
  android.view.View.requestLayout(View.java:6575)
  01-21 14:13:54.777: WARN/System.err(1156): at
  android.view.ViewGroup.removeAllViews(ViewGroup.java:2033)
  What is problem ?

 As the exception says: Only the original thread that created
 a view hierarchy can touch its views.

 Are you attempting to call setContentView() from a background thread? If
 so, arrange to call it on the UI thread, via post(), runOnUiThread(), or
 a Handler.

 --
 Mark Murphy (a Commons Guy)
 http://commonsware.com
 Android Training in Sweden -- http://www.sotrium.com/training.php

 



--~--~-~--~~~---~--~~
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: Replace the current view by an other view

2009-01-21 Thread Romain Guy

The point of runOnUiThread() *is* to run code on the UI thread.
Therefore it must NOT be used for long running operations. Usually
runOnUiThread() is invoked from another thread.

On Wed, Jan 21, 2009 at 7:50 PM, for android forandr...@gmail.com wrote:
 any help on this ??

 On Wed, Jan 21, 2009 at 8:13 PM, for android forandr...@gmail.com wrote:

 i have one question around the runOnUiThread...Basically when i used this
 method in the onCreate/onStart of the Activity,i found that it works quite
 differently than i expect..

 For example in the onCreate/onStart..say I have long running operation
 before which i want to render the UI with a progress bar.and after the long
 runnin operation is complete remove the progress bar and show the view..In
 this case I found that the UI is rendered only after the long running
 operation...so i end up not seeing the progress bar..I ended up using the
 handler...Am i going wrong in my understanding of this method?



 protected void onStart(){
 super.onStart();
 Progress Bar Visible
 runOnUiThread( new Thread() {
 // go get our feed!
 public void run() {
 //longrunning operation
  //Progress Bar Gone
  //show the required view

 }
 });
 }

 On Wed, Jan 21, 2009 at 7:55 PM, Mark Murphy mmur...@commonsware.com
 wrote:

 Nico wrote:
  Hi,
  I need to replace the current View (set by the activity.setContentView
  method) by an other.
  When I call activity.setContentView two times, I get this exception :
  01-21 14:13:54.747: WARN/System.err(1156): android.view.ViewRoot
  $CalledFromWrongThreadException: Only the original thread that created
  a view hierarchy can touch its views.
  01-21 14:13:54.757: WARN/System.err(1156): at
  android.view.ViewRoot.checkThread(ViewRoot.java:1849)
  01-21 14:13:54.757: WARN/System.err(1156): at
  android.view.ViewRoot.requestLayout(ViewRoot.java:455)
  01-21 14:13:54.767: WARN/System.err(1156): at
  android.view.View.requestLayout(View.java:6575)
  01-21 14:13:54.767: WARN/System.err(1156): at
  android.view.View.requestLayout(View.java:6575)
  01-21 14:13:54.777: WARN/System.err(1156): at
  android.view.View.requestLayout(View.java:6575)
  01-21 14:13:54.777: WARN/System.err(1156): at
  android.view.ViewGroup.removeAllViews(ViewGroup.java:2033)
  What is problem ?

 As the exception says: Only the original thread that created
 a view hierarchy can touch its views.

 Are you attempting to call setContentView() from a background thread? If
 so, arrange to call it on the UI thread, via post(), runOnUiThread(), or
 a Handler.

 --
 Mark Murphy (a Commons Guy)
 http://commonsware.com
 Android Training in Sweden -- http://www.sotrium.com/training.php





 




-- 
Romain Guy
Android framework engineer
romain...@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

--~--~-~--~~~---~--~~
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: Replace the current view by an other view

2009-01-21 Thread for android
Oh ok..I think I understand it now..

On Thu, Jan 22, 2009 at 9:23 AM, Romain Guy romain...@google.com wrote:


 The point of runOnUiThread() *is* to run code on the UI thread.
 Therefore it must NOT be used for long running operations. Usually
 runOnUiThread() is invoked from another thread.

 On Wed, Jan 21, 2009 at 7:50 PM, for android forandr...@gmail.com wrote:
  any help on this ??
 
  On Wed, Jan 21, 2009 at 8:13 PM, for android forandr...@gmail.com
 wrote:
 
  i have one question around the runOnUiThread...Basically when i used
 this
  method in the onCreate/onStart of the Activity,i found that it works
 quite
  differently than i expect..
 
  For example in the onCreate/onStart..say I have long running operation
  before which i want to render the UI with a progress bar.and after the
 long
  runnin operation is complete remove the progress bar and show the
 view..In
  this case I found that the UI is rendered only after the long running
  operation...so i end up not seeing the progress bar..I ended up using
 the
  handler...Am i going wrong in my understanding of this method?
 
 
 
  protected void onStart(){
  super.onStart();
  Progress Bar Visible
  runOnUiThread( new Thread() {
  // go get our feed!
  public void run() {
  //longrunning operation
   //Progress Bar Gone
   //show the required view
 
  }
  });
  }
 
  On Wed, Jan 21, 2009 at 7:55 PM, Mark Murphy mmur...@commonsware.com
  wrote:
 
  Nico wrote:
   Hi,
   I need to replace the current View (set by the
 activity.setContentView
   method) by an other.
   When I call activity.setContentView two times, I get this exception :
   01-21 14:13:54.747: WARN/System.err(1156): android.view.ViewRoot
   $CalledFromWrongThreadException: Only the original thread that
 created
   a view hierarchy can touch its views.
   01-21 14:13:54.757: WARN/System.err(1156): at
   android.view.ViewRoot.checkThread(ViewRoot.java:1849)
   01-21 14:13:54.757: WARN/System.err(1156): at
   android.view.ViewRoot.requestLayout(ViewRoot.java:455)
   01-21 14:13:54.767: WARN/System.err(1156): at
   android.view.View.requestLayout(View.java:6575)
   01-21 14:13:54.767: WARN/System.err(1156): at
   android.view.View.requestLayout(View.java:6575)
   01-21 14:13:54.777: WARN/System.err(1156): at
   android.view.View.requestLayout(View.java:6575)
   01-21 14:13:54.777: WARN/System.err(1156): at
   android.view.ViewGroup.removeAllViews(ViewGroup.java:2033)
   What is problem ?
 
  As the exception says: Only the original thread that created
  a view hierarchy can touch its views.
 
  Are you attempting to call setContentView() from a background thread?
 If
  so, arrange to call it on the UI thread, via post(), runOnUiThread(),
 or
  a Handler.
 
  --
  Mark Murphy (a Commons Guy)
  http://commonsware.com
  Android Training in Sweden -- http://www.sotrium.com/training.php
 
 
 
 
 
  
 



 --
 Romain Guy
 Android framework engineer
 romain...@android.com

 Note: please don't send private questions to me, as I don't have time
 to provide private support.  All such questions should be posted on
 public forums, where I and others can see and answer them

 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---