public void fieldChanged(Field arg0, int arg1) { if (arg0 == btnVoted) { // if the okay button is clicked Contestant c = getChosenContestant(); if (voteType == T_WEEKLY) { GameData.getCurrentGame().getCurrentUser().setWeeklyPick(c); } else if (voteType == T_ULTIMATE) { GameData.getCurrentGame().getCurrentUser().setUltimatePick(c); } Status.show("You chose: " + c.getFirstName() + " " + c.getLastName()); UiApplication.getUiApplication().popScreen(this); } }
public PickScreen(int voteType) { super(); this.voteType = voteType; VerticalFieldManager vertFieldManager = new VerticalFieldManager( VerticalFieldManager.USE_ALL_WIDTH | VerticalFieldManager.VERTICAL_SCROLLBAR) { // Override the paint method to draw the background image. public void paint(Graphics graphics) { graphics.setColor(Color.BLACK); graphics.fillRect(0, 0, this.getWidth(), this.getHeight()); super.paint(graphics); } }; ; try { // set up the smaller list font ff1 = FontFamily.forName("Verdana"); font2 = ff1.getFont(Font.BOLD, 20); } catch (final ClassNotFoundException cnfe) { } Vector contList = GameData.getCurrentGame().getActiveContestants(); Contestant[] contArray = new Contestant[contList.size()]; contList.copyInto(contArray); ocfActiveContestant = new ObjectChoiceField(" Cast your " + voteType + " vote: ", contArray); User user = GameData.getCurrentGame().getCurrentUser(); if (voteType == T_WEEKLY && user.getWeeklyPick() != null) { ocfActiveContestant.setSelectedIndex(user.getWeeklyPick()); } else if (voteType == T_ULTIMATE && user.getUltimatePick() != null) { ocfActiveContestant.setSelectedIndex(user.getUltimatePick()); } list = new RichList(vertFieldManager, true, 3, 0); // get all contestants for list contList = GameData.getCurrentGame().getAllContestants(); for (int i = 0; i < contList.size(); i++) { Contestant cont = (Contestant) contList.elementAt(i); /* list contains labels so that the text colour can change */ lblContName = new LabelField(cont.getFirstName() + " " + cont.getLastName(), LabelField.ELLIPSIS) { public void paint(Graphics g) { g.setColor(Color.WHITE); super.paint(g); } }; lblContName.setFont(font2); labelContTribe = new LabelField(cont.getTribe(), LabelField.ELLIPSIS) { public void paint(Graphics g) { g.setColor(Color.WHITE); super.paint(g); } }; lblContName.setFont(font2); String tempString = ""; if (cont.isCastOff()) tempString = "Castoff"; else tempString = "Active"; labelTempStatus = new LabelField(tempString, LabelField.ELLIPSIS) { public void paint(Graphics g) { g.setColor(Color.WHITE); super.paint(g); } }; lblContName.setFont(font2); Bitmap imgContestant = getImage(cont.getPicture()); list.add(new Object[] {imgContestant, lblContName, labelContTribe, labelTempStatus}); } HorizontalFieldManager horFieldManager = new HorizontalFieldManager( HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.FIELD_HCENTER) { // Override the paint method to draw the background image. public void paint(Graphics graphics) { graphics.setColor(Color.GREEN); graphics.fillRect(0, 0, this.getWidth(), this.getHeight()); super.paint(graphics); } }; ; String voted = "Vote"; user = GameData.getCurrentGame().getCurrentUser(); System.out.println(user.getWeeklyPick() + " " + this.voteType); if ((this.voteType == T_WEEKLY && user.getWeeklyPick() != null) || (this.voteType == T_ULTIMATE && user.getUltimatePick() != null)) voted = "Revote"; btnVoted = new ButtonField(voted); btnVoted.setChangeListener(this); horFieldManager.add(btnVoted); horFieldManager.add(ocfActiveContestant); horFieldManager.setFont(font2); this.setTitle(horFieldManager); this.add(vertFieldManager); this.setStatus(Common.getToolbar("Log Out")); vertFieldManager.setFocus(); // THIS NEEDS TO BE HERE. APP CRASHES WITHOUT IT }