newbie question: how to repaint the gui?

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

newbie question: how to repaint the gui?

Postby nobb » Thu Feb 11, 2010 5:14 pm

Hello,

I'm new to android and I have some trouble with the gui of my first application. I'm able to change the text property of my gui elements like text on a button. But sometimes the changes are not displayed directly. So I'm searching for some kind of method, that repaints my gui just one element on damand.
Can you help me or give me even a search term?

Thx, Nobb
nobb
Freshman
Freshman
 
Posts: 5
Joined: Thu Feb 11, 2010 4:42 pm

Top

Postby qlimax » Fri Feb 12, 2010 12:13 am

are you trying to update the ui using a thread or a timer? :roll:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby azraeal » Fri Feb 12, 2010 4:43 am

View.postInvalidate();

replace View with your UI element.
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Postby nobb » Fri Feb 12, 2010 10:37 am

I've already seen postInvalidate() in the documentation but it doesn't doesn't seem to help me. It invalidates my ui element but it doesn't repaint directly. Am I able to start the repaint manually?

I don't use any threads or timer jet.

Btw what I'm exactly trying to do: When I push a button in my ui, the application is loading data for a couple of seconds. During that time I'd like to show in a TextView 'loading part xy …'. Changing the text of the TextView (and calling postInvalidate() ) displays the text only after everything has already be loaded. That's to late. :( It seams to me, that the gui is repainted first time after pushing the button. But I'd like to start a repaint during it is pushed an everything is loading. Is there any possibility?
nobb
Freshman
Freshman
 
Posts: 5
Joined: Thu Feb 11, 2010 4:42 pm

Postby nicholas.hauschild » Fri Feb 12, 2010 2:10 pm

Hello nobb,

Is it possible to call invalidate()/postInvalidate() at the end of the method that does the loading in the TextField?

-Nick
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Postby nobb » Fri Feb 12, 2010 2:59 pm

I can call invalidate()/postInvalidate() any time. My problem is, that the changes are displayed to late. So my last idea was not only to invalidate the TextView but also to start the repaint process manually. Is that possible?

Here is a snippet of my code:
Code: Select all
class clicker implements Button.OnClickListener {
   public void onClick(View v) {
      if (v == button) {    
         [... initialize ...]
      
         for (Modul m : array) {
            text.setText("loading "+m);
            text.postInvalidate();
            // that's when I'd like to update the gui. for each module
            [... calculate ...]
         }

      }
      // that's when I see the update. I get only last message. And only after loading has been finished. :(
      
   }
}
nobb
Freshman
Freshman
 
Posts: 5
Joined: Thu Feb 11, 2010 4:42 pm

Top

Postby qlimax » Fri Feb 12, 2010 5:47 pm

Last edited by qlimax on Sun Feb 14, 2010 3:03 pm, edited 1 time in total.
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby dchanson » Sat Feb 13, 2010 5:51 pm

Could be a long-shot from left field, but could you try something like:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.          
  2.  
  3. for (Modul m : array) {
  4.  
  5.      string insert_string = "loading " + m;
  6.  
  7.      text.setText(insert_string);
  8.  
  9.      text.postInvalidate();
  10.  
  11.      // that's when I'd like to update the gui. for each module
  12.  
  13. [... calculate ...]
  14.  
  15. }
  16.  
  17.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


Perhaps the text.setText("loading " + m) is having some kind of internal issue with the concatenating at the same time the setText is called, and if you concatenated it first, it would assign properly and immediately.
Just a thought, but it doesn't look like this has been solved yet and sometimes stupid stuff like that will fix it.
dchanson
Freshman
Freshman
 
Posts: 9
Joined: Fri Feb 12, 2010 4:28 pm

Postby Moons » Sun Feb 14, 2010 10:30 am

Use a thread or a handler! The changes are not repainted, because the UI thread is busy doing some work!
Moons
Developer
Developer
 
Posts: 25
Joined: Fri Feb 13, 2009 9:19 pm

Postby nobb » Sun Feb 14, 2010 11:23 am

So it seems not possible to start te repaint manually. Calling text.setText(insert_string) doesn't helped. But the thread idea works fine for me.

Thanks for your help, especially for qlimaxs nice tutorial. 8)
nobb
Freshman
Freshman
 
Posts: 5
Joined: Thu Feb 11, 2010 4:42 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests