onClick() - refresh image issue

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

onClick() - refresh image issue

Postby ioRek » Tue Jun 23, 2009 6:49 pm

Hi,
Here is my constructor, basic one (Carte extends ImageButton)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.     public Carte(Context context,int id) {
  3.  
  4.         super(context);
  5.  
  6.  
  7.  
  8.         this.setOnClickListener(new OnClickListener() {
  9.  
  10.  
  11.  
  12.             public void onClick(View arg0) {
  13.  
  14.                 showCard();
  15.  
  16.                 if(isLost())
  17.  
  18.                   hideCard();
  19.  
  20.  
  21.  
  22.             }
  23.  
  24.         });
  25.  
  26.  
  27.  
  28.     }
  29.  
  30.  
  31.  
  32.     public void showCard() {
  33.  
  34.  
  35.  
  36.         this.setImageResource(R.drawable.lander_crashed);
  37.  
  38.         this.showed= true;
  39.  
  40.     }
  41.  
  42.  
  43.  
  44.     public void hideCard() {
  45.  
  46.  
  47.  
  48.         try {
  49.  
  50.             Thread.sleep(1000);//sleep for 1000 ms
  51.  
  52.         } catch (InterruptedException ie) {
  53.  
  54.            //If this thread was intrrupted by nother thread
  55.  
  56.         }
  57.  
  58.  
  59.  
  60.         this.setImageResource(defIm);
  61.  
  62.         this.showed= false;
  63.  
  64.        
  65.  
  66.     }
  67.  
  68.  
  69.  
  70.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

As you can see I'm just setting a different imageResource weither or not the player loose.
The problem is if the player win and so don't go throu the if and HideCard, my Image is showed but
if the player loose and I go in the if condition, even with the sleep, my "lost image" - the one in HideCard()- is shown like it didn't actually do the
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  this.setImageResource(R.drawable.lander_crashed);  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Kinda boring since I'm on it since few days !

Regards,
Jeremy
ioRek
Freshman
Freshman
 
Posts: 9
Joined: Mon Jun 22, 2009 3:10 pm

Top

Postby WarrenFaith » Tue Jun 23, 2009 8:24 pm

Changing something like the background doesn't mean it will be painted. you should invalidate() your view....
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby ioRek » Wed Jun 24, 2009 9:59 am

same result as far I can tell because the setImageResource already call the onDraw() method but at the end of onClick :(
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         this.setOnClickListener(new OnClickListener() {
  3.  
  4.  
  5.  
  6.             public void onClick(View arg0) {
  7.  
  8.                 showCard();
  9.  
  10.                 this.invalidate();
  11.  
  12.                 if(isLost())
  13.  
  14.                   hideCard();
  15.  
  16.  
  17.  
  18.             }
  19.  
  20.         });
  21.  
  22.  
  23.  
  24.     }
  25.  
  26.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Any other idea ?
ioRek
Freshman
Freshman
 
Posts: 9
Joined: Mon Jun 22, 2009 3:10 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests