2017-04-06 2 views
0

Codename 하나의 SQLite 프로젝트에서 작업 중입니다. 몇 가지 문제가 발생하는 동안 달력에서 특정 날짜를 클릭 할 때 해당 날짜가 데이터베이스에 있는지 여부를 확인합니다. 또는 아닙니다. 그러나 응용 프로그램이 시작된 후 처음으로 특정 날짜를 클릭하면 해당 날짜가 정확하게 표시되지만 두 번째로 현재 날짜 발생에 이전 날짜 발생을 추가하고 그 합계를 표시합니다. 어떻게 해결할 수 있습니까?Codename 하나의 SQLite 데이터 문제

다음은 내 코드입니다 : -이 문제에 대한 대답을 얻었다

public class Customised extends Calendar{ 
     ArrayList<String[]> data = new ArrayList<>(); 



     public Customised(){ 

    } 

    @Override 
    protected void updateButtonDayDate(Button dayButton, int currentMonth, int day) { 
      dayButton.setText(""+day); 
     dayButton.addActionListener(new ActionListener() { 
      @Override 
      public void actionPerformed(ActionEvent evt) { 

       try{ 
     cur = db.executeQuery("SELECT Date from CalendarData WHERE Date = ? ", dateLabel.getText()); 
     int 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(); 
      } 
       int i; 
       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); 
       calendar.add(container1); 
       Util.cleanup(data); 

       // dayButton.getAllStyles().setBgColor(0xef5555); 
    // dayButton.setText("* "+day); 

      }  
     }); 
    } 

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

} 
+0

날짜를 클릭 할 때 어떤 메소드가 호출됩니까? – user1506104

+0

dayButton.addActionListener (new ActionListener() { @Override public void actionPerformed (동작 이벤트 evt) { }} –

답변

1

: - 응답

@Override 
protected void updateButtonDayDate(Button dayButton, int currentMonth, int day) { 

     dayButton.setText(""+day); 
    dayButton.addActionListener(new ActionListener() { 
     @Override 
     public void actionPerformed(ActionEvent evt) { 

      try{ 
    cur = db.executeQuery("SELECT Date from CalendarData WHERE Date = ? ", dateLabel.getText()); 
    int 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); 
      if(calendar.contains(container1)== true){ 
       calendar.removeComponent(container1); 
      calendar.add(container1); 
      }else{ 
       calendar.add(container1); 
      } 

      data.clear(); 

      // dayButton.getAllStyles().setBgColor(0xef5555); 
// dayButton.setText("* "+day); 

     }  
    }); 
} 

그리고 감사합니다.

관련 문제