0
我正在Codename一個SQLite項目上工作,雖然我收到了一些問題,我試圖當我點擊日曆上的某個特定日期,然後它會檢查數據庫中是否存在該日期或者不是,但是當我在應用程序啓動後首先點擊某個特定日期時,它會準確發生該日期,但在第二次時,它會將上一個日期事件添加到當前日期事件中,並顯示該事件的總和。那我該如何解決呢?代碼名一個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;
}
}
}
在日期點擊時調用哪個方法? – user1506104
dayButton.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent evt){ }} –