Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
NGeldenhuys
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom
Accepted Solution

Rating Stars like in android

Hi all, my goal is to create a star field like in android they have a rating star field. i have come as far to accomplish the following:

  • create the star fields (5)
  • when clicked bitmap changes.
  • When "Unclicked" bitmap changes back to default.

My next step is to do the following:

if star 1 is not clicked then all 4 stars after must not be clickable, if star 2 is clicked then star 3 must be clickable and stars 4-5 must not be clickable, (and then backwards) if all 5 stars have been selected only star5 must be clickable, if star 5 and 4 are unclicked then star3must be clickable stars 2-1 must not be clickable, etc.

 

I can supply you with a code snippet with what I have done so far:

 

public class MyScreen extends MainScreen{
       boolean check=false;
       Bitmap bitmap;
       HorizontalFieldManager StarManager=new HorizontalFieldManager(USE_ALL_WIDTH);
       final Bitmap StarNotClicked = Bitmap.getBitmapResource("rating_star.png");
       final Bitmap StarClicked = Bitmap.getBitmapResource("rating_star_focus.png");
       BitmapField Star1;
       BitmapField Star2;
       BitmapField Star3;
       BitmapField Star4;
       BitmapField Star5;

       public MyScreen(){
               Star1 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
                        protected boolean navigationClick(int status, int time){
                               fieldChangeNotify(1);
                               if(check==true){
                                     this.setBitmap(StarNotClicked);
                                     check=false;
                               }else{
                                     this.setBitmap(StarClicked);
                                     check=true;
                               }
                               return true;
                         }
                };
               Star2 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
                       protected boolean navigationClick(int status, int time){
                              fieldChangeNotify(1);
                              if(check==true){
                                  this.setBitmap(StarNotClicked);
                                  check=false;
                              }else{
                                     this.setBitmap(StarClicked);
                                     check=true;
                              }
                               return true;
                       }
               };
               Star3 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
                      protected boolean navigationClick(int status, int time){
                            fieldChangeNotify(1);
                            if(check==true){
                                 this.setBitmap(StarNotClicked);
                                  check=false;
                            }else{
                                  this.setBitmap(StarClicked);
                                  check=true;
                            }
                            return true;
                       }
               };
               Star4 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
                       protected boolean navigationClick(int status, int time){
                             fieldChangeNotify(1);
                             if(check==true){
                                 this.setBitmap(StarNotClicked);
                                 check=false;
                             }else{
                                  this.setBitmap(StarClicked);
                                  check=true;

                             }
                             return true;
                        }
                };
                Star5 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
                        protected boolean navigationClick(int status, int time){
                              fieldChangeNotify(1);
                              if(check==true){
                                    this.setBitmap(StarNotClicked);
                                    check=false;
                              }else{
                                    this.setBitmap(StarClicked);
                                     check=true;
                              }
                              return true;
                       }
                };
                StarManager.add(Star1);
                StarManager.add(Star2);
                StarManager.add(Star3);
                StarManager.add(Star4);
                StarManager.add(Star5);
                 add(StarManager);
         }
}

 

Please let me know if you have any idea on how to do what I would like to achieve , thank you.

Please use plain text.
Developer
simon_hain
Posts: 15,846
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Rating Stars like in android

you store the status of all fields in a single boolean?
i would suggest that you take a look at setCookie/getCookie to store an additional status on the field.

i also wonder why you need to open a new thread about the question...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Trusted Contributor
NGeldenhuys
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: Rating Stars like in android

Okay i did some research, to get cookie -Retrieves previously set cookie, and set cookie- Sets a cookie object for later retrieval.

 

Field.setcookie(object);

Field.getCookie() ;

 

by set cookie, where the "object" is, is that where I set the "additional Status"?

 

Would you suggest I set these status's in the Navigation onclick function in my above code snippet?

 

I started a new thread because i found the answer to my previous one and now that I started a new one I also got a quick response :smileyhappy:

 

Thank you Simon_hain

Please use plain text.
Developer
simon_hain
Posts: 15,846
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Rating Stars like in android

you can use a Boolean to store a simple status with set/getCookie.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Trusted Contributor
NGeldenhuys
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: Rating Stars like in android

okay I understand how to do that... but now what i dont understand is how to make the other starfields "Unclickable". 

    Star2 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
          protected boolean navigationClick(int status, int time){
                fieldChangeNotify(1);
                if(check==true){
                      this.setBitmap(StarNotClicked);
                      check=false;
                }else{
                  this.setBitmap(StarClicked);
                  check=true;
              }
              return true;

         }
    };
as you can see here I added in the boolean to store the status , but what funcion could I use to disable the other fields, that is my problem...

Please use plain text.
Developer
simon_hain
Posts: 15,846
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Rating Stars like in android

well, this is a basic logic issue you should be able to solve yourself.

personally i would make a custom bitmapfield and give it an internal status and a method to modify it, like setClickable(boolean).
depending on the level of abstraction you want, the quick and dirty approach would be:
in field changed method, set the own field clickable to true, all others to false. if it is already clickable, reverse (all others true)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Trusted Contributor
NGeldenhuys
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: Rating Stars like in android

a friend of mine gave me a hand and this seems to do the trick (the easy long way :smileyhappy: ) :

Star1 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
protected boolean navigationClick(int status, int time){
fieldChangeNotify(1);
Star1.setBitmap(StarClicked);
Star2.setBitmap(StarNotClicked);
Star3.setBitmap(StarNotClicked);
Star4.setBitmap(StarNotClicked);
Star5.setBitmap(StarNotClicked);
return true;
}
};
Star2 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
protected boolean navigationClick(int status, int time){
fieldChangeNotify(1);
Star1.setBitmap(StarClicked);
Star2.setBitmap(StarClicked);
Star3.setBitmap(StarNotClicked);
Star4.setBitmap(StarNotClicked);
Star5.setBitmap(StarNotClicked);
return true;
}
};
Star3 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
protected boolean navigationClick(int status, int time){
fieldChangeNotify(1);

Star1.setBitmap(StarClicked);
Star2.setBitmap(StarClicked);
Star3.setBitmap(StarClicked);
Star4.setBitmap(StarNotClicked);
Star5.setBitmap(StarNotClicked);
return true;
}
};
Star4 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
protected boolean navigationClick(int status, int time){
fieldChangeNotify(1);

Star1.setBitmap(StarClicked);
Star2.setBitmap(StarClicked);
Star3.setBitmap(StarClicked);
Star4.setBitmap(StarClicked);
Star5.setBitmap(StarNotClicked);
return true;
}
};
Star5 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
protected boolean navigationClick(int status, int time){
fieldChangeNotify(1);

Star1.setBitmap(StarClicked);
Star2.setBitmap(StarClicked);
Star3.setBitmap(StarClicked);
Star4.setBitmap(StarClicked);
Star5.setBitmap(StarClicked);
return true;
}
};

Please use plain text.