代号一个日历UpdateButtonDayDate()问题

时间:2017-04-07 07:33:14

标签: java android sqlite oop codenameone

我正在处理我的项目,我希望在应用程序启动时显示日历显示,哪个日期包含事件,例如,如果日期包含事件,那么日期按钮包含*符号和日期,如果日期没有&# 39; t包含任何事件,然后它只显示一天。 我编写了以下代码,但是当我点击该按钮时它只显示*符号,那么如何管理这个代码,该代码在日期显示*符号,该日期仅包含应用程序启动时的事件或将要加载的页面。

以下是我的代码: -

    public class Customised extends Calendar{
          ArrayList<String[]> data = new ArrayList<>();
          int i,j,columns;



          @Override
          protected void updateButtonDayDate(Button dayButton,int currentMonth, int day) {
         dayButton.setText(""+day);



          dayButton.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {     
//Check which date having how many number of events===============================================================

          try{
              ShowEvent.removeAll();
          cur =  db.executeQuery("SELECT Event, Description from CalendarData  WHERE Date = ? ", dateLabel.getText());
          columns = cur.getColumnCount();
          if(columns > 0) {
          boolean next = cur.next();
          if(next) {               
          String[] columnNames = new String[columns];
          for(int iter = 0 ; iter < columns ; iter++) {
          columnNames[iter] = cur.getColumnName(iter);
          }
          while(next) {
          Row currentRow = cur.getRow();
          String[] currentRowArray = new String[columns];
          for(int iter = 0 ; iter < columns ; iter++) {
          currentRowArray[iter] = currentRow.getString(iter);
          }
          data.add(currentRowArray);
          next = cur.next();
          }
          Object[][] arr = new Object[data.size()][];
          data.toArray(arr);
          }
          }
          }catch(IOException e){
          e.printStackTrace();
          }
          for(i = 0 ; i< data.size(); i++){
          Log.p(data.get(i)[0]);
          }

          Label a = new Label(dateLabel.getText());
          Label b = new Label("          "+i);
          Container container1 = TableLayout.encloseIn(2, a,b);
          container1.setUIID("container1");

          ShowEvent.add(container1);


              for( i = 0 ; i< data.size(); i++){
              for(j = 0; j<columns; j++){
          Log.p(data.get(i)[j]);
          SpanLabel spanData = new SpanLabel(data.get(i)[j]);
          spanData.setUIID("SpanLabel");
          ShowEvent.add(spanData);    
          }
          Label space = new Label("=======================");
          ShowEvent.add(space);
          Log.p("###################");
          }
          data.clear();

          if(i>0){
              if(Dialog.show("Choose action", "What you want to do?", "Add Events","View Events")){
                  calendar.show();
              }
                  else{
                  ShowEvent.show();
              }
          }else{
              Dialog.show("Add event","There is no event to display, Please add events first","OK","");

          }
//============================================================================================================
          } 
          });
          }

          @Override
          protected void initComponent(){
              ArrayList<String[]> data1 = new ArrayList<>();
              int k;
              Log.p("initComponent");

             try{
              cur = db.executeQuery("select Date from CalendarData");
              columns = cur.getColumnCount();
          if(columns > 0) {
          boolean next = cur.next();
          if(next) {               

          String[] columnNames = new String[columns];
          for(int iter = 0 ; iter < columns ; iter++) {
          columnNames[iter] = cur.getColumnName(iter);
          }
          while(next) {
          Row currentRow = cur.getRow();
          String[] currentRowArray = new String[columns];
          for(int iter = 0 ; iter < columns ; iter++) {
          currentRowArray[iter] = currentRow.getString(iter);
          }
          data1.add(currentRowArray);
          next = cur.next();
          }
          Object[][] arr = new Object[data1.size()][];
          data1.toArray(arr);
          }
          }
          }catch(IOException e){
          e.printStackTrace();
          }
          for(k = 0 ; k< data1.size(); k++){
          Log.p(data1.get(k)[0]);

            }
          if(k>0){
              //cal.setUIID("CalendarSelectedDay");
          }

          }

          /*
          @Override
          protected boolean isInitialized(){
              boolean result = false;
              Log.p("isInitialised");
              return result;
          }*/

          public Customised(){

          }





          @Override
          protected Button createDay() {
          Button day = new Button();
          day.setAlignment(CENTER);
          day.setUIID("CalendarDay1");
          day.setEndsWith3Points(false);
          day.setTickerEnabled(false);
          return day;
          }



          }

预期结果将是: -

enter image description here

1 个答案:

答案 0 :(得分:1)

那是因为您将代码放在actionPerformed方法中,该方法仅在按下/释放按钮时触发。 将代码移动到updateButtonDayDate范围