Problem repainting absolutelayout

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

Problem repainting absolutelayout

Postby DDaan » Wed Jan 27, 2010 6:23 pm

Ok, so I am trying to repaint an absolute lay-out. I start an activity and in the onCreate method I draw my layout. And I start my timer, after two second the timer executes rearrange().

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3.         public void onCreate(Bundle icicle) {
  4.  
  5.                 // SET VIEW
  6.  
  7.                 super.onCreate(icicle);
  8.  
  9.                 this.setContentView(R.layout.myLayout);
  10.  
  11.                 updateProgressTimer.schedule(new TimerTask() {
  12.  
  13.             @Override
  14.  
  15.             public void run() {
  16.  
  17.                 // Getting imperialistic or not
  18.  
  19.                         try {
  20.  
  21.                                         rearrange();
  22.  
  23.                                 }
  24.  
  25.                         }
  26.  
  27.                         catch(Exception e)
  28.  
  29.                         {
  30.  
  31.  
  32.  
  33.                         }
  34.  
  35.            }
  36.  
  37.         }, 2000); // check after 2 seconds
  38.  
  39.         }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         void rearrange() {
  3.  
  4.                 View layout = findViewById(R.id.layLayout);
  5.  
  6.                 MyText.offsetTopAndBottom(10); //Just TextView and EditText I am rearranging
  7.  
  8.                 MyLab.offsetTopAndBottom(10);
  9.  
  10.                 layout.invalidate();
  11.  
  12.         }
  13.  
  14.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Then I hoped this would redraw everything at the fixed position, but it doesn't. I wonder why, because when I add a button and execute the same method (rearrange) after I clicked it it works fine.

It's for a school project which I have to finish in two days :oops: , so please help quickly. Thanks in advantage.
DDaan
Freshman
Freshman
 
Posts: 4
Joined: Wed Jan 27, 2010 6:11 pm

Top

Postby qlimax » Wed Jan 27, 2010 6:39 pm

you have to use a Handler to do that
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby DDaan » Wed Jan 27, 2010 7:40 pm

Ok, so I replaced the timer for the Handler.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.  
  3.      public void onCreate(Bundle icicle) {
  4.  
  5.           // SET VIEW
  6.  
  7.           super.onCreate(icicle);
  8.  
  9.           this.setContentView(R.layout.myLayout);
  10.  
  11.           Handler hand = new Handler();
  12.  
  13.           hand.postAtTime(rearrange(), 5000000););
  14.  
  15.      }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


But there's a problem... this is executed before my layout is drawn... this is not what I want... :? Anyway to fix it? There probably is so the question should be anyone can help me? :P

PS: hand.postDelayed(rearrange(), 5000000); doesn't seem to fix the problem either.
DDaan
Freshman
Freshman
 
Posts: 4
Joined: Wed Jan 27, 2010 6:11 pm

Postby qlimax » Wed Jan 27, 2010 7:56 pm

something like this?


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3.      public void onCreate(Bundle icicle) {
  4.  
  5.           // SET VIEW
  6.  
  7.           super.onCreate(icicle);
  8.  
  9.           this.setContentView(R.layout.myLayout);        
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  final Handler handler =new Handler(new Callback() {
  16.  
  17.                        
  18.  
  19.                         @Override
  20.  
  21.                         public boolean handleMessage(Message msg) {
  22.  
  23.                                 rearrange();
  24.  
  25.                                 return true;
  26.  
  27.                         }
  28.  
  29.                 });
  30.  
  31.        
  32.  
  33.        
  34.  
  35.  
  36.  
  37. updateProgressTimer.schedule(new TimerTask() {
  38.  
  39.             @Override
  40.  
  41.             public void run() {
  42.  
  43.                // Getting imperialistic or not
  44.  
  45.                try {
  46.  
  47.                          
  48.  
  49.  handler.sendEmptyMessage(0);
  50.  
  51.                     }
  52.  
  53.                }
  54.  
  55.                catch(Exception e)
  56.  
  57.                {
  58.  
  59.  
  60.  
  61.                }
  62.  
  63.            }
  64.  
  65.         }, 2000); // check after 2 seconds
  66.  
  67.  
  68.  
  69.  
  70.  
  71. }
Parsed in 0.046 seconds, using GeSHi 1.0.8.4
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby DDaan » Wed Jan 27, 2010 8:24 pm

Great it works brilliant! Thank you very much for your quick and helpful replies.

Though it's kind of hard to see someone fix a problem I have been working on for hours. :P
DDaan
Freshman
Freshman
 
Posts: 4
Joined: Wed Jan 27, 2010 6:11 pm

Postby qlimax » Wed Jan 27, 2010 9:12 pm

You are more than welcome, I'm glad I could help.
:wink:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Top

Postby pskink » Thu Jan 28, 2010 9:11 am

DDaan wrote:Ok, so I replaced the timer for the Handler.

PS: hand.postDelayed(rearrange(), 5000000); doesn't seem to fix the problem either.


what about
hand.postDelayed(rearrange(), 2000);
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 11 guests