Redraw Sceen

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Redraw Sceen

Postby ansh.chauhan » Wed Jun 17, 2009 7:58 am

Hi Evryone i came here after one year.Nice to see evryone

My problem is that i want to redraw screen i mean like j2me we use repaint()...how we can redraw onDraw function

Thanx Evrybody for ur great support on this site
ansh.chauhan
Experienced Developer
Experienced Developer
 
Posts: 75
Joined: Tue May 27, 2008 7:04 am

Top

Postby serkan.dogantekin » Thu Jun 18, 2009 7:30 am

You can use View's invalidate method
serkan.dogantekin
Developer
Developer
 
Posts: 27
Joined: Thu Jun 04, 2009 6:12 pm
Location: Istanbul/Turkey

Postby ansh.chauhan » Thu Jun 18, 2009 10:42 am

Thanx buddy...now i m getting problem when i m using invalidate inside run() its doesnt calling onDraw fucntion
ansh.chauhan
Experienced Developer
Experienced Developer
 
Posts: 75
Joined: Tue May 27, 2008 7:04 am

Postby serkan.dogantekin » Thu Jun 18, 2009 1:08 pm

You are using a "run" method, so i am assuming that you are creating a runnable and in its "run" method trying to call invalidate.

If this is a correct assumption, it is OK to get a problem because if you are not in the ui thread, you cannot execute operations on visual items.

So what to do???

A simple solution is creating a handler in the activity -so it will be bound to the ui thread- (and define it so that when it receives a message, it will call invalidate etc), and in the runnable.run posting this handler a message (it can be an empty message).
serkan.dogantekin
Developer
Developer
 
Posts: 27
Joined: Thu Jun 04, 2009 6:12 pm
Location: Istanbul/Turkey

Postby ansh.chauhan » Thu Jun 18, 2009 1:41 pm

Thanx buddy


But i dont know how to use handler .can you help me about it
ansh.chauhan
Experienced Developer
Experienced Developer
 
Posts: 75
Joined: Tue May 27, 2008 7:04 am

Postby serkan.dogantekin » Thu Jun 18, 2009 2:10 pm

a semi-pseudo code will be like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class X extends Activity {
  2.  
  3.         protected void onCreate(Bundle savedInstanceState) {
  4.  
  5.                 super.onCreate(savedInstanceState);
  6.  
  7.                 final View Y = findViewById(...);
  8.  
  9.                 final Handler handler = new Handler() {
  10.  
  11.                         public void handleMessage(Message msg) {
  12.  
  13.                              Y.invalidate();                  
  14.  
  15.                         }
  16.  
  17.                 };
  18.  
  19.  
  20.  
  21.                Thread dummyThread = new Thread(new Runnable() {
  22.  
  23.                         public void run() {
  24.  
  25.                            // do some work here
  26.  
  27.                            handler.sendEmptyMessage(0);
  28.  
  29.                         }              
  30.  
  31.                });
  32.  
  33.                dummyThread.start();
  34.  
  35.                //rest
  36.  
  37.         }
  38.  
  39. }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
serkan.dogantekin
Developer
Developer
 
Posts: 27
Joined: Thu Jun 04, 2009 6:12 pm
Location: Istanbul/Turkey

Top

Postby ansh.chauhan » Thu Jun 18, 2009 2:22 pm

Greate job buddy

Thanx for that...tell me one more thing will this code effect our memory(Like heap in j2me)
ansh.chauhan
Experienced Developer
Experienced Developer
 
Posts: 75
Joined: Tue May 27, 2008 7:04 am

Postby serkan.dogantekin » Thu Jun 18, 2009 3:15 pm

if the previous notes help you in someway, it is reallly a pleasure for me :)

for the memory, i am not sure about what is in your mind but it is said to handle "handlers" in an activity in activity's "onDestroy" method (when you create a handler, it will be bound to thread's message queue, so clear this queue in "onDestroy" method by using "removeCallbacks" methods), but the best is to check the memory usage and threads through the adb (i will try to check these tonight)
serkan.dogantekin
Developer
Developer
 
Posts: 27
Joined: Thu Jun 04, 2009 6:12 pm
Location: Istanbul/Turkey

Postby ansh.chauhan » Fri Jun 19, 2009 5:18 am

Yup buddy it helps me too much...u hav done such a great job..
thanx for that
ansh.chauhan
Experienced Developer
Experienced Developer
 
Posts: 75
Joined: Tue May 27, 2008 7:04 am

Postby virtual » Fri Jun 19, 2009 6:30 am

Or you can use postInvalidate() of View from non UI Thread.
Regards,
Virtual
virtual
Developer
Developer
 
Posts: 26
Joined: Tue Mar 24, 2009 11:20 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests