My requirement is to create 5 stars when i click bitmap changes,When "Unclicked" bitmap changes back to default.and 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.
public class Starscreen extends MainScreen
{
protected static BitmapField Star1 = null;
protected static BitmapField Star2 = null;
protected static BitmapField Star4 = null;
protected static BitmapField Star5 = null;
protected static final Bitmap StarClicked = null;
protected static BitmapField Star3 = null;
BitmapField bitmapField1;
private Bitmap StarNotClicked;
public Starscreen(Secondscreen secondscreen)
{
setTitle("Star Screen");
LabelField RateDeal = new LabelField("Rating: ");
Mainlayout.add(RateDeal);
HorizontalFieldManager StarManager=new HorizontalFieldManager
(USE_ALL_WIDTH);
final Bitmap StarNotClicked = Bitmap.getBitmapResource("Star3.png");
final Bitmap StarClicked = Bitmap.getBitmapResource("Star4.png");
Star1 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
private Object StarClicked;
protected boolean navigationClick(int status, int time){
fieldChangeNotify(1);
Star1.setBitmap((Bitmap) StarClicked);
Star2.setBitmap(StarNotClicked);
Star3.setBitmap(StarNotClicked);
Star4.setBitmap(StarNotClicked);
Star5.setBitmap(StarNotClicked);
AmountOfStarsSelected(1);
return true;
}
};
Star2 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
private Object StarClicked;
protected boolean navigationClick(int status, int time){
fieldChangeNotify(1);
Star1.setBitmap((Bitmap) StarClicked);
Star2.setBitmap((Bitmap) StarClicked);
Star3.setBitmap(StarNotClicked);
Star4.setBitmap(StarNotClicked);
Star5.setBitmap(StarNotClicked);
AmountOfStarsSelected(2);
return true;
}
};
Star3 = new BitmapField(StarNotClicked,BitmapField.FOCUSABLE){
// private Object StarClicked;
protected boolean navigationClick(int status, int time){
fieldChangeNotify(1);
Star1.setBitmap((Bitmap) StarClicked);
Star2.setBitmap((Bitmap) StarClicked);
Star3.setBitmap((Bitmap) 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);
Mainlayout.add(StarManager);
add(Mainlayout);
}
}
By executing above code i am getting an error and it shows create method for AmountOfStarsSelected(); but i dont have any idea what condition should i use inside AmountOfStarsSelected(); please help me i am new to blackberry
I'd say make a separate class for this, extended from
HorizontalFieldManager. Have that class create the 5 buttons and lay them out, and contain a local state variableint level. Create a publicsetLevel(int level)andgetLevel()method in this class. Where level refers to the star currently selected.In
setLevelput the following code:In each of your stars you should call this
setLevelmethodRemember that in your constructor you should set level to -1, then call setLevel(0) so that the first star can be selected by default.