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(check link) with what I have done so far: http://supportforums.blackberry.com/t5/Java-Development/Rating-Stars-like-in-android/m-p/1942559

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

有帮助吗?

解决方案 2

LabelField RateDeal = new LabelField("Rating: ");
    HorizontalFieldManager StarManager=new HorizontalFieldManager(USE_ALL_WIDTH);
    final Bitmap StarNotClicked = Bitmap.getBitmapResource("rating_star.png");
    final Bitmap StarClicked = Bitmap.getBitmapResource("rating_star_focus.png");

    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);
            AmountOfStarsSelected(1);
            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);
            AmountOfStarsSelected(2);
            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);
            AmountOfStarsSelected(3);
            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);
            AmountOfStarsSelected(4);
            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);
            AmountOfStarsSelected(5);
            return true;
        }
    };
    StarManager.add(Star1);
    StarManager.add(Star2);
    StarManager.add(Star3);
    StarManager.add(Star4);
    StarManager.add(Star5);
        add(StarManager);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top